home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / helpful.zip / scsiprog < prev    next >
Text File  |  1995-08-21  |  130KB  |  2,755 lines

  1.   The Linux SCSI programming HOWTO
  2.   Heiko Eissfeldt heiko@colossus.escape.de
  3.   v1.4, 14 June 1995
  4.  
  5.   This document deals with programming the Linux generic SCSI interface.
  6.  
  7.   1.  Introduction
  8.  
  9.   This document is a guide to the installation and programming of the
  10.   Linux generic SCSI interface.
  11.  
  12.   It covers kernel prerequisites, device mappings, and basic interaction
  13.   with devices. Some simple C programming examples are included.
  14.   General knowledge of the SCSI command set is required; for more
  15.   information on the SCSI standard and related information, see the
  16.   appendix to this document.
  17.  
  18.   Note the plain text version of this document lacks cross references
  19.   (they show up as ``'').
  20.  
  21.  
  22.   2.  What Is The Generic SCSI Interface?
  23.  
  24.   The generic SCSI interface has been implemented to provide general
  25.   SCSI access to (possibly exotic) pieces of SCSI hardware. It was
  26.   developed by Lawrence Foard ( entropy@world.std.com) and sponsored by
  27.   Killy Corporation (see the comments in drivers/scsi/sg.h).
  28.  
  29.   The interface makes special device handling possible from user level
  30.   applications (i.e. outside the kernel). Thus, kernel driver
  31.   development, which is more risky and difficult to debug, is not
  32.   necessary.
  33.  
  34.   However, if you don't program the driver properly it is possible to
  35.   hang the SCSI bus, the driver, or the kernel. Therefore, it is
  36.   important to properly program the generic driver and to first back up
  37.   all files to avoid losing data. Another useful thing to do before
  38.   running your programs is to issue a sync command to ensure that any
  39.   buffers are flushed to disk, minimizing data loss if the system hangs.
  40.  
  41.   Another advantage of the generic driver is that as long as the
  42.   interface itself does not change, all applications are independent of
  43.   new kernel development. In comparison, other low-level kernel drivers
  44.   have to be synchronized with other internal kernel changes.
  45.  
  46.   Typically, the generic driver is used to communicate with new SCSI
  47.   hardware devices that require special user applications to be written
  48.   to take advantage of their features (e.g. scanners, printers, CD-ROM
  49.   jukeboxes). The generic interface allows these to be written quickly.
  50.  
  51.  
  52.   3.  What Are The Requirements To Use It?
  53.  
  54.  
  55.   3.1.  Kernel Configuration
  56.  
  57.   You must have a supported SCSI controller, obviously. Furthermore,
  58.   your kernel must have controller support as well as generic support
  59.   compiled in. Configuring the Linux kernel (via make config under
  60.   /usr/src/linux) typically looks like the following:
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.    ...
  68.   *
  69.   * SCSI support
  70.   *
  71.   SCSI support? (CONFIG_SCSI) [n] y
  72.   *
  73.   * SCSI support type (disk, tape, CDrom)
  74.   *
  75.    ...
  76.   Scsi generic support (CONFIG_CHR_DEV_SG) [n] y
  77.   *
  78.   * SCSI low-level drivers
  79.   *
  80.    ...
  81.  
  82.  
  83.  
  84.  
  85.   If available, modules can of course be build instead.
  86.  
  87.  
  88.   3.2.  Device Files
  89.  
  90.   The generic SCSI driver uses its own device files, separate from those
  91.   used by the other SCSI device drivers. They can be generated using the
  92.   MAKEDEV script, typically found in the /dev directory. Running MAKEDEV
  93.   sg produces these files:
  94.  
  95.  
  96.  
  97.        crw-------   1 root     system    21,   0 Aug 20 20:09 /dev/sga
  98.        crw-------   1 root     system    21,   1 Aug 20 20:09 /dev/sgb
  99.        crw-------   1 root     system    21,   2 Aug 20 20:09 /dev/sgc
  100.        crw-------   1 root     system    21,   3 Aug 20 20:09 /dev/sgd
  101.        crw-------   1 root     system    21,   4 Aug 20 20:09 /dev/sge
  102.        crw-------   1 root     system    21,   5 Aug 20 20:09 /dev/sgf
  103.        crw-------   1 root     system    21,   6 Aug 20 20:09 /dev/sgg
  104.        crw-------   1 root     system    21,   7 Aug 20 20:09 /dev/sgh
  105.                                           |    |
  106.                                       major,   minor device numbers
  107.  
  108.  
  109.  
  110.  
  111.   Note that these are character devices for raw access. On some systems
  112.   these devices may be called /dev/{sg0,sg1,...}, depending on your
  113.   installation, so adjust the following examples accordingly.
  114.  
  115.  
  116.   3.3.  Device Mapping
  117.  
  118.   These device files are dynamically mapped to SCSI id/LUNs on your SCSI
  119.   bus (LUN = logical unit). The mapping allocates devices consecutively
  120.   for each LUN of each device on each SCSI bus found at time of the SCSI
  121.   scan, beginning at the lower LUNs/ids/buses. It starts with the first
  122.   SCSI controller and continues without interruption with all following
  123.   controllers. This is currently done in the initialisation of the SCSI
  124.   driver.
  125.  
  126.   For example, assuming you had three SCSI devices hooked up with ids 1,
  127.   3, and 5 on the first SCSI bus (each having one LUN), then the
  128.   following mapping would be in effect:
  129.  
  130.  
  131.  
  132.  
  133.   /dev/sga -> SCSI id 1
  134.   /dev/sgb -> SCSI id 3
  135.   /dev/sgc -> SCSI id 5
  136.  
  137.  
  138.  
  139.  
  140.   If you now add a new device with id 4, then the mapping (after the
  141.   next rescan) will be:
  142.  
  143.  
  144.  
  145.        /dev/sga -> SCSI id 1
  146.        /dev/sgb -> SCSI id 3
  147.        /dev/sgc -> SCSI id 4
  148.        /dev/sgd -> SCSI id 5
  149.  
  150.  
  151.  
  152.  
  153.   Notice the change for id 5 -- the corresponding device is no longer
  154.   mapped to /dev/sgc but is now /dev/sgd.
  155.  
  156.  
  157.   3.3.1.  Rescanning the devices
  158.  
  159.   To force a rescan, a modularized driver could be deleted and
  160.   reinserted. At initialisation time it will rescan its bus.  But in
  161.   order to be able to delete the driver, none of its devices may be in
  162.   use at that time. When adding more devices to the scsi bus keep in
  163.   mind there are limited spare entries for new devices. The memory had
  164.   been allocated at boot time and has room for 2 more devices.
  165.  
  166.   Scanning the scsi buses on your own for all luns is not recommended.
  167.   There are too many (buggy) devices that may hang the scsi bus, when
  168.   being addressed with a LUN value that is not 0. The kernel manages a
  169.   private table with known flawed devices, where it scans with LUN 0
  170.   only. Newer kernels scan at default with lun 0 only.
  171.  
  172.  
  173.   4.  Programmers Guide
  174.  
  175.   The following sections are for programmers who want to use the generic
  176.   SCSI interface in their own applications. An example will be given
  177.   showing how to access a SCSI device with the INQUIRY and the
  178.   TESTUNITREADY commands.
  179.  
  180.  
  181.   When using these code examples, note the following:
  182.  
  183.   o  the generic SCSI interface was extended in kernel version 1.1.68;
  184.      the examples require at least this version. But please avoid kernel
  185.      version 1.1.77 up to 1.1.89 since they had a broken generic scsi
  186.      interface.
  187.  
  188.   o  the constant DEVICE in the header section describing the accessed
  189.      device should be set according to your available devices (see
  190.      section ``''.
  191.  
  192.  
  193.   5.  Overview Of Device Programming
  194.  
  195.   The header file drivers/scsi/sg.h under the Linux source tree contains
  196.   a description of the interface (this is based on kernel version
  197.   1.1.68):
  198.  
  199.        struct sg_header
  200.         {
  201.          int pack_len;
  202.                           /* length of incoming packet <4096 (including header) */
  203.          int reply_len;   /* maximum length <4096 of expected reply */
  204.          int pack_id;     /* id number of packet */
  205.          int result;      /* 0==ok, otherwise refer to errno codes */
  206.          unsigned int twelve_byte:1;
  207.                       /* Force 12 byte command length for group 6 & 7 commands  */
  208.          unsigned int other_flags:31;                  /* for future use */
  209.          unsigned char sense_buffer[16]; /* used only by reads */
  210.          /* command follows then data for command */
  211.         };
  212.  
  213.  
  214.  
  215.  
  216.  
  217.   This structure describes how a SCSI command is to be processed and has
  218.   room to hold the results of the execution of the command.  The
  219.   individual structure components will be discussed later in section
  220.   ``''.
  221.  
  222.   The general way of exchanging data with the generic driver is as
  223.   follows: to send a command to an opened generic device, write() a
  224.   block containing these three parts to it:
  225.  
  226.  
  227.  
  228.  
  229.  
  230.                                     struct sg_header
  231.                                       SCSI command
  232.                                        output data
  233.  
  234.  
  235.  
  236.  
  237.  
  238.   To obtain the result of a command, read() a block with this (similar)
  239.   block structure:
  240.  
  241.  
  242.  
  243.                                     struct sg_header
  244.                                        input data
  245.  
  246.  
  247.  
  248.  
  249.  
  250.   This is a general overview of the process. The following sections
  251.   describe each of the steps in more detail.
  252.  
  253.   NOTE: Up to recent kernel versions, it is necessary to block the
  254.   SIGINT signal between the write() and the corresponding read() call
  255.   (i.e. via sigprocmask()). A return after the write() part without any
  256.   read() to fetch the results will block on subsequent accesses. This
  257.   signal blocking has not yet been included in the example code. So
  258.   better do not issue SIGINT (a la ^C) when running these examples.
  259.  
  260.  
  261.   6.  Opening The Device
  262.  
  263.   A generic device has to be opened for read and write access:
  264.  
  265.                int fd = open (device_name, O_RDWR);
  266.  
  267.  
  268.  
  269.  
  270.   (This is the case even for a read-only hardware device such as a cdrom
  271.   drive).
  272.  
  273.   We have to perform a write to send the command and a read to get back
  274.   any results. In the case of an error the return code is negative (see
  275.   section ``'' for a complete list).
  276.  
  277.  
  278.   7.  The Header Structure
  279.  
  280.  
  281.  
  282.   The header structure struct sg_header serves as a controlling layer
  283.   between the application and the kernel driver.  We now discuss its
  284.   components in detail.
  285.  
  286.  
  287.  
  288.      int pack_len
  289.         defines the size of the block written to the driver.  This is
  290.         defined within the kernel for internal use.
  291.  
  292.      int reply_len
  293.         defines the size of the block to be accepted at reply.  This is
  294.         defined from the application side.
  295.  
  296.  
  297.      int pack_id
  298.         This field helps to assign replies to requests. The application
  299.         can supply a unique id for each request. Suppose you have
  300.         written several commands (say 4) to one device. They may work in
  301.         parallel, one being the fastest. When getting replies via 4
  302.         reads, the replies do not have to have the order of the
  303.         requests. To identify the correct reply for a given request one
  304.         can use the pack_id field. Typically its value is incremented
  305.         after each request (and wraps eventually). The maximum amount of
  306.         outstanding requests is limited by the kernel to SG_MAX_QUEUE
  307.         (eg 4).
  308.  
  309.  
  310.      int result
  311.         the result code of a read or write call.  This is defined from
  312.         the generic driver (kernel) side.  These codes are defined in
  313.         errno.h (0 meaning no error).
  314.  
  315.  
  316.      unsigned int twelve_byte:1
  317.         This field is necessary only when using non-standard vendor
  318.         specific commands (in the range 0xc0 - 0xff).  When these
  319.         commands have a command length of 12 bytes instead of 10, this
  320.         field has to be set to one before the write call. Other command
  321.         lengths are not supported. This is defined from the application
  322.         side.
  323.  
  324.  
  325.      unsigned char sense_buffer[16]
  326.         This buffer is set after a command is completed (after a read()
  327.         call) and contains the SCSI sense code. Some command results
  328.         have to be read from here (e.g. for TESTUNITREADY). Usually it
  329.         contains just zero bytes.  The value in this field is set by the
  330.         generic driver (kernel) side.
  331.   The following example function interfaces directly with the generic
  332.   kernel driver. It defines the header structure, sends the command via
  333.   write, gets the result via read and does some (limited) error
  334.   checking.  The sense buffer data is available in the output buffer
  335.   (unless a NULL pointer has been given, in which case it's in the input
  336.   buffer). We will use it in the examples which follow.
  337.  
  338.   Note: Set the value of DEVICE to your device descriptor.
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.   #define DEVICE "/dev/sgc"
  398.  
  399.   /* Example program to demonstrate the generic SCSI interface */
  400.   #include <stdio.h>
  401.   #include <unistd.h>
  402.   #include <string.h>
  403.   #include <fcntl.h>
  404.   #include <errno.h>
  405.   #include <linux/../../drivers/scsi/sg.h>
  406.  
  407.  
  408.   #define SCSI_OFF sizeof(struct sg_header)
  409.   static unsigned char cmd[SCSI_OFF + 18];      /* SCSI command buffer */
  410.   int fd;                               /* SCSI device/file descriptor */
  411.  
  412.   /* process a complete SCSI cmd. Use the generic SCSI interface. */
  413.   static int handle_SCSI_cmd(unsigned cmd_len,         /* command length */
  414.                              unsigned in_size,         /* input data size */
  415.                              unsigned char *i_buff,    /* input buffer */
  416.                              unsigned out_size,        /* output data size */
  417.                              unsigned char *o_buff     /* output buffer */
  418.                              )
  419.   {
  420.       int status = 0;
  421.       struct sg_header *sg_hd;
  422.  
  423.       /* safety checks */
  424.       if (!cmd_len) return -1;            /* need a cmd_len != 0 */
  425.       if (!i_buff) return -1;             /* need an input buffer != NULL */
  426.   #ifdef SG_BIG_BUFF
  427.       if (SCSI_OFF + cmd_len + in_size > SG_BIG_BUFF) return -1;
  428.       if (SCSI_OFF + out_size > SG_BIG_BUFF) return -1;
  429.   #else
  430.       if (SCSI_OFF + cmd_len + in_size > 4096) return -1;
  431.       if (SCSI_OFF + out_size > 4096) return -1;
  432.   #endif
  433.  
  434.       if (!o_buff) out_size = 0;      /* no output buffer, no output size */
  435.  
  436.       /* generic SCSI device header construction */
  437.       sg_hd = (struct sg_header *) i_buff;
  438.       sg_hd->reply_len   = SCSI_OFF + out_size;
  439.       sg_hd->twelve_byte = cmd_len == 12;
  440.   #if     0
  441.       sg_hd->pack_len    = SCSI_OFF + cmd_len + in_size; /* not necessary */
  442.       sg_hd->pack_id;     /* not used */
  443.       sg_hd->other_flags; /* not used */
  444.   #endif
  445.  
  446.       /* send command */
  447.       status = write( fd, i_buff, SCSI_OFF + cmd_len + in_size );
  448.       if ( status < 0 || status != SCSI_OFF + cmd_len + in_size ||
  449.                          sg_hd->result ) {
  450.           /* some error happened */
  451.           fprintf( stderr, "write(generic) result = 0x%x cmd = 0x%x\n",
  452.                       sg_hd->result, i_buff[SCSI_OFF] );
  453.           perror("");
  454.           return status;
  455.       }
  456.  
  457.       if (!o_buff) o_buff = i_buff;       /* buffer pointer check */
  458.  
  459.       /* retrieve result */
  460.       status = read( fd, o_buff, SCSI_OFF + out_size);
  461.       if ( status < 0 || status != SCSI_OFF + out_size || sg_hd->result ) {
  462.           /* some error happened */
  463.           fprintf( stderr, "read(generic) status = 0x%x, result = 0x%x, "
  464.                            "cmd = 0x%x\n",
  465.                            status, sg_hd->result, o_buff[SCSI_OFF] );
  466.           fprintf( stderr, "read(generic) sense "
  467.                   "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
  468.                   sg_hd->sense_buffer[0],         sg_hd->sense_buffer[1],
  469.                   sg_hd->sense_buffer[2],         sg_hd->sense_buffer[3],
  470.                   sg_hd->sense_buffer[4],         sg_hd->sense_buffer[5],
  471.                   sg_hd->sense_buffer[6],         sg_hd->sense_buffer[7],
  472.                   sg_hd->sense_buffer[8],         sg_hd->sense_buffer[9],
  473.                   sg_hd->sense_buffer[10],        sg_hd->sense_buffer[11],
  474.                   sg_hd->sense_buffer[12],        sg_hd->sense_buffer[13],
  475.                   sg_hd->sense_buffer[14],        sg_hd->sense_buffer[15]);
  476.       }
  477.       /* Look if we got what we expected to get */
  478.       if (status == SCSI_OFF + out_size) status = 0; /* got them all */
  479.  
  480.       return status;  /* 0 means no error */
  481.   }
  482.  
  483.  
  484.  
  485.  
  486.   While this may look somewhat complex at first appearance, most of the
  487.   code is for error checking and reporting (which is useful even after
  488.   the code is working).
  489.  
  490.   Handle_SCSI_cmd has a generalized form for all SCSI commands types,
  491.   falling into each of these categories:
  492.  
  493.  
  494.  
  495.  
  496.               Data Mode              | Example Command
  497.        ===============================================
  498.        neither input nor output data | test unit ready
  499.         no input data, output data   | inquiry, read
  500.         input data, no output data   | mode select, write
  501.           input data, output data    | mode sense
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.   8.  Inquiry Command Example
  509.  
  510.   One of the most basic SCSI commands is the INQUIRY command, used to
  511.   identify the type and make of the device. Here is the definition from
  512.   the SCSI-2 specification (for details refer to the SCSI-2 standard).
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.                               Table 44: INQUIRY Command
  530.   +=====-========-========-========-========-========-========-========-========+
  531.   |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  532.   |Byte |        |        |        |        |        |        |        |        |
  533.   |=====+=======================================================================|
  534.   | 0   |                           Operation Code (12h)                        |
  535.   |-----+-----------------------------------------------------------------------|
  536.   | 1   | Logical Unit Number      |                  Reserved         |  EVPD  |
  537.   |-----+-----------------------------------------------------------------------|
  538.   | 2   |                           Page Code                                   |
  539.   |-----+-----------------------------------------------------------------------|
  540.   | 3   |                           Reserved                                    |
  541.   |-----+-----------------------------------------------------------------------|
  542.   | 4   |                           Allocation Length                           |
  543.   |-----+-----------------------------------------------------------------------|
  544.   | 5   |                           Control                                     |
  545.   +=============================================================================+
  546.  
  547.  
  548.  
  549.  
  550.   The output data are as follows:
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.  
  558.  
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566.  
  567.  
  568.  
  569.  
  570.  
  571.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.                        Table 45: Standard INQUIRY Data Format
  596.   +=====-========-========-========-========-========-========-========-========+
  597.   |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  598.   |Byte |        |        |        |        |        |        |        |        |
  599.   |=====+==========================+============================================|
  600.   | 0   | Peripheral Qualifier     |           Peripheral Device Type           |
  601.   |-----+-----------------------------------------------------------------------|
  602.   | 1   |  RMB   |                  Device-Type Modifier                        |
  603.   |-----+-----------------------------------------------------------------------|
  604.   | 2   |   ISO Version   |       ECMA Version       |  ANSI-Approved Version   |
  605.   |-----+-----------------+-----------------------------------------------------|
  606.   | 3   |  AENC  | TrmIOP |     Reserved    |         Response Data Format      |
  607.   |-----+-----------------------------------------------------------------------|
  608.   | 4   |                           Additional Length (n-4)                     |
  609.   |-----+-----------------------------------------------------------------------|
  610.   | 5   |                           Reserved                                    |
  611.   |-----+-----------------------------------------------------------------------|
  612.   | 6   |                           Reserved                                    |
  613.   |-----+-----------------------------------------------------------------------|
  614.   | 7   | RelAdr | WBus32 | WBus16 |  Sync  | Linked |Reserved| CmdQue | SftRe  |
  615.   |-----+-----------------------------------------------------------------------|
  616.   | 8   | (MSB)                                                                 |
  617.   |- - -+---                        Vendor Identification                    ---|
  618.   | 15  |                                                                 (LSB) |
  619.   |-----+-----------------------------------------------------------------------|
  620.   | 16  | (MSB)                                                                 |
  621.   |- - -+---                        Product Identification                   ---|
  622.   | 31  |                                                                 (LSB) |
  623.   |-----+-----------------------------------------------------------------------|
  624.   | 32  | (MSB)                                                                 |
  625.   |- - -+---                        Product Revision Level                   ---|
  626.   | 35  |                                                                 (LSB) |
  627.   |-----+-----------------------------------------------------------------------|
  628.   | 36  |                                                                       |
  629.   |- - -+---                        Vendor Specific                          ---|
  630.   | 55  |                                                                       |
  631.   |-----+-----------------------------------------------------------------------|
  632.   | 56  |                                                                       |
  633.   |- - -+---                        Reserved                                 ---|
  634.   | 95  |                                                                       |
  635.   |=====+=======================================================================|
  636.   |     |                       Vendor-Specific Parameters                      |
  637.   |=====+=======================================================================|
  638.   | 96  |                                                                       |
  639.   |- - -+---                        Vendor Specific                          ---|
  640.   | n   |                                                                       |
  641.   +=============================================================================+
  642.  
  643.  
  644.  
  645.  
  646.  
  647.   The next example uses the low-level function handle_SCSI_cmd to
  648.   perform the Inquiry SCSI command.
  649.  
  650.   We first append the command block to the generic header, then call
  651.   handle_SCSI_cmd.  Note that the output buffer size argument for the
  652.   handle_SCSI_cmd call excludes the generic header size.  After command
  653.   completion the output buffer contains the requested data, unless an
  654.   error occurred.
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.   #define INQUIRY_CMD     0x12
  662.   #define INQUIRY_CMDLEN  6
  663.   #define INQUIRY_REPLY_LEN 96
  664.   #define INQUIRY_VENDOR  8       /* Offset in reply data to vendor name */
  665.  
  666.   /* request vendor brand and model */
  667.   static unsigned char *Inquiry ( void )
  668.   {
  669.     unsigned char Inqbuffer[ SCSI_OFF + INQUIRY_REPLY_LEN ];
  670.     unsigned char cmdblk [ INQUIRY_CMDLEN ] =
  671.         { INQUIRY_CMD,  /* command */
  672.                     0,  /* lun/reserved */
  673.                     0,  /* page code */
  674.                     0,  /* reserved */
  675.     INQUIRY_REPLY_LEN,  /* allocation length */
  676.                     0 };/* reserved/flag/link */
  677.  
  678.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  679.  
  680.     /*
  681.      * +------------------+
  682.      * | struct sg_header | <- cmd
  683.      * +------------------+
  684.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  685.      * +------------------+
  686.      */
  687.  
  688.     if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd,
  689.                         sizeof(Inqbuffer) - SCSI_OFF, Inqbuffer )) {
  690.         fprintf( stderr, "Inquiry failed\n" );
  691.         exit(2);
  692.     }
  693.     return (Inqbuffer + SCSI_OFF);
  694.   }
  695.  
  696.  
  697.  
  698.  
  699.   The example above follows this structure. The Inquiry function copies
  700.   its command block behind the generic header (given by SCSI_OFF). Input
  701.   data is not present for this command.  Handle_SCSI_cmd will define the
  702.   header structure. We can now implement the function main to complete
  703.   this working example program.
  704.  
  705.  
  706.  
  707.        void main( void )
  708.        {
  709.          fd = open(DEVICE, O_RDWR);
  710.          if (fd < 0) {
  711.            fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  712.            exit(1);
  713.          }
  714.  
  715.          /* print some fields of the Inquiry result */
  716.          printf( "%s\n", Inquiry() + INQUIRY_VENDOR );
  717.        }
  718.  
  719.  
  720.  
  721.  
  722.   We first open the device, check for errors, and then call the higher
  723.   level subroutine. Then we print the results in human readable format
  724.   including the vendor, product, and revision.
  725.  
  726.  
  727.   Note: There is more information in the Inquiry result than this little
  728.   program gives. You may want to extend the program to give device type,
  729.   ANSI version etc. The device type is of special importance, since it
  730.   determines the mandatory and optional command sets for this device.
  731.   If you don't want to program it yourself, you may want to use the
  732.   scsiinfo program from Eric Youngdale, which requests nearly all
  733.   information about an SCSI device. Look at tsx-11.mit.edu in
  734.   pub/Linux/ALPHA/scsi.
  735.  
  736.  
  737.   9.  The Sense Buffer
  738.  
  739.  
  740.   Commands with no output data can give status information via the sense
  741.   buffer (which is part of the header structure).  Sense data is
  742.   available when the previous command has terminated with a CHECK
  743.   CONDITION status. In this case the kernel automatically retrieves the
  744.   sense data via a REQUEST SENSE command. Its structure is:
  745.  
  746.  
  747.  
  748.  
  749.        +=====-========-========-========-========-========-========-========-========+
  750.        |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  751.        |Byte |        |        |        |        |        |        |        |        |
  752.        |=====+========+==============================================================|
  753.        | 0   | Valid  |                  Error Code (70h or 71h)                     |
  754.        |-----+-----------------------------------------------------------------------|
  755.        | 1   |                           Segment Number                              |
  756.        |-----+-----------------------------------------------------------------------|
  757.        | 2   |Filemark|  EOM   |  ILI   |Reserved|         Sense Key                 |
  758.        |-----+-----------------------------------------------------------------------|
  759.        | 3   | (MSB)                                                                 |
  760.        |- - -+---                        Information                              ---|
  761.        | 6   |                                                                 (LSB) |
  762.        |-----+-----------------------------------------------------------------------|
  763.        | 7   |                           Additional Sense Length (n-7)               |
  764.        |-----+-----------------------------------------------------------------------|
  765.        | 8   | (MSB)                                                                 |
  766.        |- - -+---                        Command-Specific Information             ---|
  767.        | 11  |                                                                 (LSB) |
  768.        |-----+-----------------------------------------------------------------------|
  769.        | 12  |                           Additional Sense Code                       |
  770.        |-----+-----------------------------------------------------------------------|
  771.        | 13  |                           Additional Sense Code Qualifier             |
  772.        |-----+-----------------------------------------------------------------------|
  773.        | 14  |                           Field Replaceable Unit Code                 |
  774.        |-----+-----------------------------------------------------------------------|
  775.        | 15  |  SKSV  |                                                              |
  776.        |- - -+------------               Sense-Key Specific                       ---|
  777.        | 17  |                                                                       |
  778.        |-----+-----------------------------------------------------------------------|
  779.        | 18  |                                                                       |
  780.        |- - -+---                        Additional Sense Bytes                   ---|
  781.        | n   |                                                                       |
  782.        +=============================================================================+
  783.  
  784.  
  785.  
  786.  
  787.  
  788.   Note: The most useful fields are Sense Key (see section ``''),
  789.   Additional Sense Code and Additional Sense Code Qualifier (see section
  790.   ``''). The latter two are used combined as a pair.
  791.  
  792.  
  793.   10.  Example Using Sense Buffer
  794.  
  795.   Here we will use the TEST UNIT READY command to check whether media is
  796.   loaded into our device. The header declarations and function
  797.   handle_SCSI_cmd from the inquiry example will be needed as well.
  798.  
  799.  
  800.  
  801.  
  802.                                Table 73: TEST UNIT READY Command
  803.        +=====-========-========-========-========-========-========-========-========+
  804.        |  Bit|   7    |   6    |   5    |   4    |   3    |   2    |   1    |   0    |
  805.        |Byte |        |        |        |        |        |        |        |        |
  806.        |=====+=======================================================================|
  807.        | 0   |                           Operation Code (00h)                        |
  808.        |-----+-----------------------------------------------------------------------|
  809.        | 1   | Logical Unit Number      |                  Reserved                  |
  810.        |-----+-----------------------------------------------------------------------|
  811.        | 2   |                           Reserved                                    |
  812.        |-----+-----------------------------------------------------------------------|
  813.        | 3   |                           Reserved                                    |
  814.        |-----+-----------------------------------------------------------------------|
  815.        | 4   |                           Reserved                                    |
  816.        |-----+-----------------------------------------------------------------------|
  817.        | 5   |                           Control                                     |
  818.        +=============================================================================+
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.   Here is the function which implements it:
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.   #define TESTUNITREADY_CMD 0
  860.   #define TESTUNITREADY_CMDLEN 6
  861.  
  862.   #define ADD_SENSECODE 12
  863.   #define ADD_SC_QUALIFIER 13
  864.   #define NO_MEDIA_SC 0x3a
  865.   #define NO_MEDIA_SCQ 0x00
  866.  
  867.   int TestForMedium ( void )
  868.   {
  869.     /* request READY status */
  870.     static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
  871.         TESTUNITREADY_CMD, /* command */
  872.                         0, /* lun/reserved */
  873.                         0, /* reserved */
  874.                         0, /* reserved */
  875.                         0, /* reserved */
  876.                         0};/* control */
  877.  
  878.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  879.  
  880.     /*
  881.      * +------------------+
  882.      * | struct sg_header | <- cmd
  883.      * +------------------+
  884.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  885.      * +------------------+
  886.      */
  887.  
  888.     if (handle_SCSI_cmd(sizeof(cmdblk), 0, cmd,
  889.                               0, NULL)) {
  890.         fprintf (stderr, "Test unit ready failed\n");
  891.         exit(2);
  892.     }
  893.  
  894.     return
  895.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SENSECODE) !=
  896.                                                           NO_MEDIA_SC ||
  897.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SC_QUALIFIER) !=
  898.                                                           NO_MEDIA_SCQ;
  899.   }
  900.  
  901.  
  902.  
  903.  
  904.   Combined with this main function we can do the check.
  905.  
  906.  
  907.  
  908.        void main( void )
  909.        {
  910.          fd = open(DEVICE, O_RDWR);
  911.          if (fd < 0) {
  912.            fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  913.            exit(1);
  914.          }
  915.  
  916.          /* look if medium is loaded */
  917.  
  918.          if (!TestForMedium()) {
  919.            printf("device is unloaded\n");
  920.          } else {
  921.            printf("device is loaded\n");
  922.          }
  923.        }
  924.  
  925.   The file generic_demo.c from the appendix contains both examples.
  926.  
  927.  
  928.   11.  Ioctl Functions
  929.  
  930.  
  931.   There are two ioctl functions available:
  932.  
  933.   o  ioctl(fd, SG_SET_TIMEOUT, &Timeout); sets the timeout value to
  934.      Timeout * 10 milliseconds. Timeout has to be declared as int.
  935.  
  936.   o  ioctl(fd, SG_GET_TIMEOUT, &Timeout); gets the current timeout
  937.      value.  Timeout has to be declared as int.
  938.  
  939.  
  940.   12.  Driver Defaults
  941.  
  942.  
  943.   12.1.  Transfer Lengths
  944.  
  945.  
  946.   Currently (at least up to kernel version 1.1.68) input and output
  947.   sizes have to be less than or equal than 4096 bytes unless the kernel
  948.   has been compiled with SG_BIG_BUFF defined, if which case it is
  949.   limited to SG_BIG_BUFF (e.g. 32768) bytes.  These sizes include the
  950.   generic header as well as the command block on input.
  951.  
  952.  
  953.   12.2.  Timeout And Retry Values
  954.  
  955.   The default timeout value is set to one minute (Timeout = 6000).  It
  956.   can be changed through an ioctl call (see section ``'').  The default
  957.   number of retries is one.
  958.  
  959.  
  960.   13.  Obtaining The Scsi Specifications
  961.  
  962.   There are standards entitled SCSI-1 and SCSI-2 (and possibly soon
  963.   SCSI-3). The standards are mostly upward compatible.
  964.  
  965.   The SCSI-1 standard is (in the author's opinion) mostly obsolete, and
  966.   SCSI-2 is the most widely used. SCSI-3 is very new and very expensive.
  967.   These standardized command sets specify mandatory and optional
  968.   commands for SCSI manufacturers and should be preferred over the
  969.   vendor specific command extensions which are not standardized and for
  970.   which programming information is seldom available. Of course sometimes
  971.   there is no alternative to these extensions.
  972.  
  973.  
  974.   Electronic copies are available via anonymous ftp from:
  975.  
  976.   o  ftp.cs.tulane.edu:pub/scsi
  977.  
  978.   o  ncrinfo.ncr.com:/pub/standards
  979.  
  980.   o  ftp.cs.uni-sb.de:/pub/misc/doc/scsi
  981.  
  982.   (I got my SCSI specification from the Yggdrasil Linux CD-ROM in the
  983.   directory /usr/doc/scsi-2 and /usr/doc/scsi-1).
  984.  
  985.   The SCSI FAQ also lists the following sources of printed information:
  986.  
  987.   The SCSI specification: Available from:
  988.  
  989.  
  990.  
  991.         Global Engineering Documents
  992.         15 Inverness Way East
  993.         Englewood Co  80112-5704
  994.         (800) 854-7179
  995.           SCSI-1: X3.131-1986
  996.           SCSI-2: X3.131-199x
  997.           SCSI-3 X3T9.2/91-010R4 Working Draft
  998.  
  999.   (Global Engineering Documentation in Irvine, CA (714)261-1455??)
  1000.  
  1001.   SCSI-1: Doc \# X3.131-1986 from ANSI, 1430 Broadway, NY, NY 10018
  1002.  
  1003.   IN-DEPTH EXPLORATION OF SCSI can be obtained from
  1004.   Solution Technology, Attn: SCSI Publications, POB 104, Boulder Creek,
  1005.   CA 95006, (408)338-4285, FAX (408)338-4374
  1006.  
  1007.   THE SCSI ENCYLOPEDIA and the SCSI BENCH REFERENCE can be obtained from
  1008.   ENDL Publishing, 14426 Black Walnut Ct., Saratoga, CA 95090,
  1009.   (408)867-6642, FAX (408)867-2115
  1010.  
  1011.   SCSI: UNDERSTANDING THE SMALL COMPUTER SYSTEM INTERFACE was published
  1012.   by Prentice-Hall, ISBN 0-13-796855-8
  1013.  
  1014.  
  1015.  
  1016.  
  1017.  
  1018.   14.  Related Information Sources
  1019.  
  1020.  
  1021.   14.1.  HOWTOs and FAQs
  1022.  
  1023.   The Linux SCSI-HOWTO by Drew Eckhardt covers all supported SCSI
  1024.   controllers as well as device specific questions. A lot of
  1025.   troubleshooting hints are given. It is available from sunsite.unc.edu
  1026.   in /pub/Linux/docs/LDP and its mirror sites.
  1027.  
  1028.   General questions about SCSI are answered in the SCSI-FAQ from the
  1029.   newsgroup Comp.Periphs.Scsi (available on tsx-11 in
  1030.   pub/linux/ALPHA/scsi and mirror sites).
  1031.  
  1032.  
  1033.   14.2.  Mailing list
  1034.  
  1035.   There is a mailing list for bug reports and questions regarding SCSI
  1036.   development under Linux.  To join, send email to
  1037.   majordomo@vger.rutgers.edu with the line subscribe linux-scsi in the
  1038.   body of the message.  Messages should be posted to linux-
  1039.   scsi@vger.rutgers.edu.  Help text can be requested by sending the
  1040.   message line "help" to majordomo@vger.rutgers.edu.
  1041.  
  1042.  
  1043.   14.3.  Example code
  1044.  
  1045.  
  1046.      sunsite.unc.edu: apps/graphics/hpscanpbm-0.3a.tar.gz
  1047.         This package handles a HP scanjet scanner through the generic
  1048.         interface.
  1049.  
  1050.      tsx-11.mit.edu: BETA/cdrom/private/mkisofs/cdwrite-1.3.tar.gz
  1051.         The cdwrite package uses the generic interface to write a cd
  1052.         image to a cd writer.
  1053.  
  1054.      sunsite.unc.edu: apps/sound/cds/cdda2wav*.src.tar.gz
  1055.         A shameless plug for my own application, which copies audio cd
  1056.         tracks into wav files.
  1057.   15.  Other useful stuff
  1058.  
  1059.   Things that may come in handy. I don't have no idea if there are newer
  1060.   or better versions around. Feedback is welcome.
  1061.  
  1062.  
  1063.   15.1.  Device driver writer helpers
  1064.  
  1065.   These documents can be found at the sunsite.unc.edu ftp server and its
  1066.   mirrors.
  1067.  
  1068.      /pub/Linux/docs/kernel/kernel-hackers-guide
  1069.         The LDP kernel hackers guide. May be a bit outdated, but covers
  1070.         the most fundamental things.
  1071.  
  1072.      /pub/Linux/docs/kernel/drivers.doc.z
  1073.         This document covers writing character drivers.
  1074.  
  1075.      /pub/Linux/docs/kernel/tutorial.doc.z
  1076.         Tutorial on writing a character device driver with code.
  1077.  
  1078.      /pub/Linux/docs/kernel/scsi.paper.tar.gz
  1079.         A Latex document describing howto write a SCSI driver.
  1080.  
  1081.      /pub/Linux/docs/hardware/DEVICES
  1082.         A list of device majors and minors used by Linux.
  1083.  
  1084.  
  1085.   15.2.  Utilities
  1086.  
  1087.  
  1088.      tsx-11.mit.edu: ALPHA/scsi/scsiinfo*.tar.gz
  1089.         Program to query a scsi device for operating parameters, defect
  1090.         lists, etc.  An X-based interface is availalble that requires
  1091.         that you have Tk/Tcl/wish installed.  With the X-based interface
  1092.         you can easily alter the settings on the drive.
  1093.  
  1094.      tsx-11.mit.edu: ALPHA/kdebug
  1095.         A gdb extension for kernel debugging.
  1096.  
  1097.  
  1098.  
  1099.  
  1100.   16.  Other SCSI Access Interfaces
  1101.  
  1102.   In Linux there is also another SCSI access via SCSI_IOCTL_SEND_COMMAND
  1103.   ioctl calls, which require root priviledges. The scsiinfo as well as
  1104.   the cdda2wav package utilizes it.
  1105.  
  1106.  
  1107.   There are some other similar interfaces in use in the un*x world, but
  1108.   not available for Linux:
  1109.  
  1110.   1. CAM (Common Access Method) developed by Future Domain and other
  1111.      SCSI vendors. Linux has little support for a SCSI CAM system yet
  1112.      (mainly for booting from hard disk).  CAM even supports target
  1113.      mode, so one could disguise ones computer as a peripheral hardware
  1114.      device (e.g. for a small SCSI net).
  1115.  
  1116.   2. ASPI (Advanced SCSI Programming Interface) developed by Adaptec.
  1117.      This is the de facto standard for MS-DOS machines.
  1118.  
  1119.   There are other application interfaces from SCO(TM), NeXT(TM), Silicon
  1120.   Graphics(TM) and SUN(TM) as well.
  1121.  
  1122.  
  1123.   17.  Final Comments
  1124.  
  1125.   The generic SCSI interface bridges the gap between user applications
  1126.   and specific devices. But rather than bloating a lot of programs with
  1127.   similar sets of low-level functions, it would be more desirable to
  1128.   have a shared library with a generalized set of low-level functions
  1129.   for a particular purpose.  The main goal should be to have independent
  1130.   layers of interfaces.  A good design would separate an application
  1131.   into low-level and hardware independent routines. The low-level
  1132.   routines could be put into a shared library and made available for all
  1133.   applications. Here, standardized interfaces should be followed as much
  1134.   as possible before making new ones.
  1135.  
  1136.   By now you should know more than I do about the Linux generic SCSI
  1137.   interface. So you can start developing powerful applications for the
  1138.   benefit of the global Linux community now...
  1139.  
  1140.  
  1141.   18.  Acknowledgments
  1142.  
  1143.   Special thanks go to Jeff Tranter for proofreading and enhancing the
  1144.   text considerably as well as to Carlos Puchol for useful comments.
  1145.   Drew Eckhardt's and Eric Youngdale's help on my first (dumb) questions
  1146.   about the use of this interface has been appreciated.
  1147.  
  1148.  
  1149.   S.  Appendix
  1150.  
  1151.  
  1152.   T.  Error handling
  1153.  
  1154.  
  1155.   The functions open, ioctl, write and read can report errors. In this
  1156.   case their return value is -1 and the global variable errno is set to
  1157.   the error number (negative).  The errno values are defined in
  1158.   /usr/include/errno.h.  Possible negative values are:
  1159.  
  1160.  
  1161.  
  1162.        Function | Error        | Description
  1163.        =========|==============|=============================================
  1164.        open     | -ENXIO       | not a valid device
  1165.                 | -EACCES      | access mode is not read/write (O_RDWR)
  1166.                 | -EBUSY       | device was requested for nonblocking access,
  1167.                 |              | but is busy now.
  1168.                 | -ERESTARTSYS | this indicates an internal error. Try to
  1169.                 |              | make it reproducible and inform the SCSI
  1170.                 |              | channel (for details on bug reporting
  1171.                 |              | see Drew Eckhardts SCSI-HOWTO).
  1172.        ioctl    | -ENXIO       | not a valid device
  1173.        read     | -EWOULDBLOCK | the device would block. Try again later.
  1174.        write    | -EIO         | the length is too small (smaller than the
  1175.                 |              | generic header struct). Caution: Currently
  1176.                 |              | there is no overlength checking.
  1177.                 | -EWOULDBLOCK | the device would block. Try again later.
  1178.                 | -ERESTARTSYS | this indicates an internal error. Try to
  1179.                 |              | make it reproducible and inform the SCSI
  1180.                 |              | channel (for details on bug reporting
  1181.                 |              | see Drew Eckhardts SCSI-HOWTO).
  1182.                 | -ENOMEM      | memory required for this request could not be
  1183.                 |              | allocated. Try later again unless you
  1184.                 |              | exceeded the maximum transfer size (see above)
  1185.  
  1186.  
  1187.  
  1188.  
  1189.   For read/write positive return values indicate as usual the amount of
  1190.   bytes that have been successfully transferred. This should equal the
  1191.   amount you requested.
  1192.  
  1193.  
  1194.   T.1.  Error status decoding
  1195.  
  1196.  
  1197.   Furthermore a detailed reporting is done via the kernels hd_status and
  1198.   the devices sense_buffer (see section ``'') both from the generic
  1199.   header structure.
  1200.  
  1201.   The meaning of hd_status can be found in drivers/scsi/scsi.h: This
  1202.   unsigned int is composed out of different parts:
  1203.  
  1204.  
  1205.  
  1206.  
  1207.          lsb  |    ...    |    ...    | msb
  1208.        =======|===========|===========|============
  1209.        status | sense key | host code | driver byte
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215.   These macros from drivers/scsi/scsi.h can be used to separate the
  1216.   fields:
  1217.  
  1218.  
  1219.  
  1220.                Macro          | Description
  1221.        =======================|=================================================
  1222.        status_byte(hd_status) | The SCSI device status. See section Status codes
  1223.        msg_byte(hd_status)    | From the device. See section SCSI sense keys
  1224.        host_byte(hd_status)   | From the kernel. See section Hostcodes
  1225.        driver_byte(hd_status) | From the kernel. See section midlevel codes
  1226.  
  1227.  
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.   T.2.  Status codes
  1234.  
  1235.  
  1236.   The following status codes from the SCSI device (defined in
  1237.   drivers/scsi/scsi.h) should be used with the macro status_byte (see
  1238.   section ``''):
  1239.  
  1240.  
  1241.  
  1242.        Value | Symbol
  1243.        ======|=====================
  1244.        0x00  | GOOD
  1245.        0x01  | CHECK_CONDITION
  1246.        0x02  | CONDITION_GOOD
  1247.        0x04  | BUSY
  1248.        0x08  | INTERMEDIATE_GOOD
  1249.        0x0a  | INTERMEDIATE_C_GOOD
  1250.        0x0c  | RESERVATION_CONFLICT
  1251.  
  1252.  
  1253.  
  1254.  
  1255.   Note that these symbol values have been shifted right once.  When the
  1256.   status is CHECK_CONDITION, the sense data in the sense buffer is valid
  1257.   (check especially the additional sense code and additional sense code
  1258.   qualifier).
  1259.  
  1260.   These values carry the meaning from the SCSI-2 specification:
  1261.  
  1262.  
  1263.  
  1264.  
  1265.  
  1266.  
  1267.  
  1268.  
  1269.  
  1270.  
  1271.  
  1272.  
  1273.  
  1274.  
  1275.  
  1276.  
  1277.  
  1278.  
  1279.  
  1280.  
  1281.  
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.  
  1297.  
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304.  
  1305.  
  1306.  
  1307.  
  1308.  
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.                              Table 27: Status Byte Code
  1322.   +=================================-==============================+
  1323.   |       Bits of Status Byte       |  Status                      |
  1324.   |  7   6   5   4   3   2   1   0  |                              |
  1325.   |---------------------------------+------------------------------|
  1326.   |  R   R   0   0   0   0   0   R  |  GOOD                        |
  1327.   |  R   R   0   0   0   0   1   R  |  CHECK CONDITION             |
  1328.   |  R   R   0   0   0   1   0   R  |  CONDITION MET               |
  1329.   |  R   R   0   0   1   0   0   R  |  BUSY                        |
  1330.   |  R   R   0   1   0   0   0   R  |  INTERMEDIATE                |
  1331.   |  R   R   0   1   0   1   0   R  |  INTERMEDIATE-CONDITION MET  |
  1332.   |  R   R   0   1   1   0   0   R  |  RESERVATION CONFLICT        |
  1333.   |  R   R   1   0   0   0   1   R  |  COMMAND TERMINATED          |
  1334.   |  R   R   1   0   1   0   0   R  |  QUEUE FULL                  |
  1335.   |                                 |                              |
  1336.   |       All Other Codes           |  Reserved                    |
  1337.   |----------------------------------------------------------------|
  1338.   |  Key: R = Reserved bit                                         |
  1339.   +================================================================+
  1340.  
  1341.   A definition of the status byte codes is given below.
  1342.  
  1343.   GOOD.  This status indicates that the target has successfully completed the
  1344.   command.
  1345.  
  1346.   CHECK CONDITION.  This status indicates that a contingent allegiance condition
  1347.   has occurred (see 6.6).
  1348.  
  1349.   CONDITION MET.  This status or INTERMEDIATE-CONDITION MET is returned whenever
  1350.   the requested operation is satisfied (see the SEARCH DATA and PRE-FETCH
  1351.   commands).
  1352.  
  1353.   BUSY.  This status indicates that the target is busy.  This status shall be
  1354.   returned whenever a target is unable to accept a command from an otherwise
  1355.   acceptable initiator (i.e., no reservation conflicts).  The recommended
  1356.   initiator recovery action is to issue the command again at a later time.
  1357.  
  1358.   INTERMEDIATE.  This status or INTERMEDIATE-CONDITION MET shall be returned for
  1359.   every successfully completed command in a series of linked commands (except
  1360.   the last command), unless the command is terminated with CHECK CONDITION,
  1361.   RESERVATION CONFLICT, or COMMAND TERMINATED status.  If INTERMEDIATE or
  1362.   INTERMEDIATE-CONDITION MET status is not returned, the series of linked
  1363.   commands is terminated and the I/O process is ended.
  1364.  
  1365.   INTERMEDIATE-CONDITION MET.  This status is the combination of the CONDITION
  1366.   MET and INTERMEDIATE statuses.
  1367.  
  1368.   RESERVATION CONFLICT.  This status shall be returned whenever an initiator
  1369.   attempts to access a logical unit or an extent within a logical unit that is
  1370.   reserved with a conflicting reservation type for another SCSI device (see the
  1371.   RESERVE and RESERVE UNIT commands).  The recommended initiator recovery action
  1372.   is to issue the command again at a later time.
  1373.  
  1374.   COMMAND TERMINATED.  This status shall be returned whenever the target
  1375.   terminates the current I/O process after receiving a TERMINATE I/O PROCESS
  1376.   message (see 5.6.22).  This status also indicates that a contingent allegiance
  1377.   condition has occurred (see 6.6).
  1378.  
  1379.   QUEUE FULL.  This status shall be implemented if tagged queuing is
  1380.   implemented.  This status is returned when a SIMPLE QUEUE TAG, ORDERED QUEUE
  1381.   TAG, or HEAD OF QUEUE TAG message is received and the command queue is full.
  1382.   The I/O process is not placed in the command queue.
  1383.  
  1384.  
  1385.  
  1386.  
  1387.   T.3.  SCSI Sense Keys
  1388.  
  1389.  
  1390.   The sense key from the result should be retrieved with the macro
  1391.   msg_byte (see section ``'').  These kernel symbols (from
  1392.   drivers/scsi/scsi.h) are predefined:
  1393.  
  1394.  
  1395.  
  1396.        Value | Symbol
  1397.        ======|================
  1398.        0x00  | NO_SENSE
  1399.        0x01  | RECOVERED_ERROR
  1400.        0x02  | NOT_READY
  1401.        0x03  | MEDIUM_ERROR
  1402.        0x04  | HARDWARE_ERROR
  1403.        0x05  | ILLEGAL_REQUEST
  1404.        0x06  | UNIT_ATTENTION
  1405.        0x07  | DATA_PROTECT
  1406.        0x08  | BLANK_CHECK
  1407.        0x0a  | COPY_ABORTED
  1408.        0x0b  | ABORTED_COMMAND
  1409.        0x0d  | VOLUME_OVERFLOW
  1410.        0x0e  | MISCOMPARE
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.   A verbatim list from the SCSI-2 doc follows (from section 7.2.14.3):
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.                       Table 69: Sense Key (0h-7h) Descriptions
  1454.   +========-====================================================================+
  1455.   | Sense  |  Description                                                       |
  1456.   |  Key   |                                                                    |
  1457.   |--------+--------------------------------------------------------------------|
  1458.   |   0h   |  NO SENSE.  Indicates that there is no specific sense key          |
  1459.   |        |  information to be reported for the designated logical unit.  This |
  1460.   |        |  would be the case for a successful command or a command that      |
  1461.   |        |  received CHECK CONDITION or COMMAND TERMINATED status because one |
  1462.   |        |  of the filemark, EOM, or ILI bits is set to one.                  |
  1463.   |--------+--------------------------------------------------------------------|
  1464.   |   1h   |  RECOVERED ERROR.  Indicates that the last command completed       |
  1465.   |        |  successfully with some recovery action performed by the target.   |
  1466.   |        |  Details may be determinable by examining the additional sense     |
  1467.   |        |  bytes and the information field.  When multiple recovered errors  |
  1468.   |        |  occur during one command, the choice of which error to report     |
  1469.   |        |  (first, last, most severe, etc.) is device specific.              |
  1470.   |--------+--------------------------------------------------------------------|
  1471.   |   2h   |  NOT READY.  Indicates that the logical unit addressed cannot be   |
  1472.   |        |  accessed.  Operator intervention may be required to correct this  |
  1473.   |        |  condition.                                                        |
  1474.   |--------+--------------------------------------------------------------------|
  1475.   |   3h   |  MEDIUM ERROR.  Indicates that the command terminated with a non-  |
  1476.   |        |  recovered error condition that was probably caused by a flaw in   |
  1477.   |        |  the medium or an error in the recorded data.  This sense key may  |
  1478.   |        |  also be returned if the target is unable to distinguish between a |
  1479.   |        |  flaw in the medium and a specific hardware failure (sense key 4h).|
  1480.   |--------+--------------------------------------------------------------------|
  1481.   |   4h   |  HARDWARE ERROR.  Indicates that the target detected a non-        |
  1482.   |        |  recoverable hardware failure (for example, controller failure,    |
  1483.   |        |  device failure, parity error, etc.) while performing the command  |
  1484.   |        |  or during a self test.                                            |
  1485.   |--------+--------------------------------------------------------------------|
  1486.   |   5h   |  ILLEGAL REQUEST.  Indicates that there was an illegal parameter in|
  1487.   |        |  the command descriptor block or in the additional parameters      |
  1488.   |        |  supplied as data for some commands (FORMAT UNIT, SEARCH DATA,     |
  1489.   |        |  etc.).  If the target detects an invalid parameter in the command |
  1490.   |        |  descriptor block, then it shall terminate the command without     |
  1491.   |        |  altering the medium.  If the target detects an invalid parameter  |
  1492.   |        |  in the additional parameters supplied as data, then the target may|
  1493.   |        |  have already altered the medium.  This sense key may also indicate|
  1494.   |        |  that an invalid IDENTIFY message was received (5.6.7).            |
  1495.   |--------+--------------------------------------------------------------------|
  1496.   |   6h   |  UNIT ATTENTION.  Indicates that the removable medium may have been|
  1497.   |        |  changed or the target has been reset.  See 6.9 for more detailed  |
  1498.   |        |  information about the unit attention condition.                   |
  1499.   |--------+--------------------------------------------------------------------|
  1500.   |   7h   |  DATA PROTECT.  Indicates that a command that reads or writes the  |
  1501.   |        |  medium was attempted on a block that is protected from this       |
  1502.   |        |  operation.  The read or write operation is not performed.         |
  1503.   +=============================================================================+
  1504.  
  1505.                       Table 70: Sense Key (8h-Fh) Descriptions
  1506.   +========-====================================================================+
  1507.   | Sense  |  Description                                                       |
  1508.   |  Key   |                                                                    |
  1509.   |--------+--------------------------------------------------------------------|
  1510.   |   8h   |  BLANK CHECK.  Indicates that a write-once device or a sequential- |
  1511.   |        |  access device encountered blank medium or format-defined end-of-  |
  1512.   |        |  data indication while reading or a write-once device encountered a|
  1513.   |        |  non-blank medium while writing.                                   |
  1514.   |--------+--------------------------------------------------------------------|
  1515.   |   9h   |  Vendor Specific.  This sense key is available for reporting vendor|
  1516.   |        |  specific conditions.                                              |
  1517.   |--------+--------------------------------------------------------------------|
  1518.   |   Ah   |  COPY ABORTED.  Indicates a COPY, COMPARE, or COPY AND VERIFY      |
  1519.   |        |  command was aborted due to an error condition on the source       |
  1520.   |        |  device, the destination device, or both.  (See 7.2.3.2 for        |
  1521.   |        |  additional information about this sense key.)                     |
  1522.   |--------+--------------------------------------------------------------------|
  1523.   |   Bh   |  ABORTED COMMAND.  Indicates that the target aborted the command.  |
  1524.   |        |  The initiator may be able to recover by trying the command again. |
  1525.   |--------+--------------------------------------------------------------------|
  1526.   |   Ch   |  EQUAL.  Indicates a SEARCH DATA command has satisfied an equal    |
  1527.   |        |  comparison.                                                       |
  1528.   |--------+--------------------------------------------------------------------|
  1529.   |   Dh   |  VOLUME OVERFLOW.  Indicates that a buffered peripheral device has |
  1530.   |        |  reached the end-of-partition and data may remain in the buffer    |
  1531.   |        |  that has not been written to the medium.  A RECOVER BUFFERED DATA |
  1532.   |        |  command(s) may be issued to read the unwritten data from the      |
  1533.   |        |  buffer.                                                           |
  1534.   |--------+--------------------------------------------------------------------|
  1535.   |   Eh   |  MISCOMPARE.  Indicates that the source data did not match the data|
  1536.   |        |  read from the medium.                                             |
  1537.   |--------+--------------------------------------------------------------------|
  1538.   |   Fh   |  RESERVED.                                                         |
  1539.   +=============================================================================+
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.   T.4.  Hostcodes
  1547.  
  1548.  
  1549.   The following host codes are defined in drivers/scsi/scsi.h. They are
  1550.   set by the kernel driver and should be used with the macro host_byte
  1551.   (see section ``''):
  1552.  
  1553.  
  1554.  
  1555.        Value | Symbol         | Description
  1556.        ======|================|========================================
  1557.        0x00  | DID_OK         | No error
  1558.        0x01  | DID_NO_CONNECT | Couldn't connect before timeout period
  1559.        0x02  | DID_BUS_BUSY   | BUS stayed busy through time out period
  1560.        0x03  | DID_TIME_OUT   | TIMED OUT for other reason
  1561.        0x04  | DID_BAD_TARGET | BAD target
  1562.        0x05  | DID_ABORT      | Told to abort for some other reason
  1563.        0x06  | DID_PARITY     | Parity error
  1564.        0x07  | DID_ERROR      | internal error
  1565.        0x08  | DID_RESET      | Reset by somebody
  1566.        0x09  | DID_BAD_INTR   | Got an interrupt we weren't expecting
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.   T.5.  Driver codes
  1573.  
  1574.  
  1575.   The midlevel driver categorizes the returned status from the lowlevel
  1576.   driver based on the sense key from the device. It suggests some
  1577.   actions to be taken such as retry, abort or remap. The routine
  1578.   scsi_done from scsi.c does a very differentiated handling based on
  1579.   host_byte(), status_byte(), msg_byte() and the suggestion. It then
  1580.   sets the driver byte to show what it has done. The driver byte is
  1581.   composed out of two nibbles: the driver status and the suggestion.
  1582.   Each half is composed from the below values being 'or'ed together
  1583.   (found in scsi.h).
  1584.  
  1585.        Value | Symbol         | Description of Driver status
  1586.        ======|================|========================================
  1587.        0x00  | DRIVER_OK      | No error
  1588.        0x01  | DRIVER_BUSY    | not used
  1589.        0x02  | DRIVER_SOFT    | not used
  1590.        0x03  | DRIVER_MEDIA   | not used
  1591.        0x04  | DRIVER_ERROR   | internal driver error
  1592.        0x05  | DRIVER_INVALID | finished (DID_BAD_TARGET or DID_ABORT)
  1593.        0x06  | DRIVER_TIMEOUT | finished with timeout
  1594.        0x07  | DRIVER_HARD    | finished with fatal error
  1595.        0x08  | DRIVER_SENSE   | had sense information available
  1596.  
  1597.  
  1598.  
  1599.  
  1600.  
  1601.  
  1602.        Value | Symbol         | Description of suggestion
  1603.        ======|================|========================================
  1604.        0x10  | SUGGEST_RETRY  | retry the SCSI request
  1605.        0x20  | SUGGEST_ABORT  | abort the request
  1606.        0x30  | SUGGEST_REMAP  | remap the block (not yet implemented)
  1607.        0x40  | SUGGEST_DIE    | let the kernel panic
  1608.        0x80  | SUGGEST_SENSE  | get sense information from the device
  1609.        0xff  | SUGGEST_IS_OK  | nothing to be done
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.   U.  Additional sense codes and additional sense code qualifiers
  1616.  
  1617.  
  1618.   When the status of the executed SCSI command is CHECK_CONDITION, sense
  1619.   data is available in the sense buffer. The additional sense code and
  1620.   additional sense code qualifier are contained in that buffer.
  1621.  
  1622.   From the SCSI-2 specification I include two tables. The first is in
  1623.   lexical, the second in numerical order.
  1624.  
  1625.  
  1626.   U.1.  ASC and ASCQ in lexical order
  1627.  
  1628.   The following table list gives a list of descriptions and device types
  1629.   they apply to.
  1630.  
  1631.  
  1632.  
  1633.  
  1634.  
  1635.  
  1636.  
  1637.  
  1638.  
  1639.  
  1640.  
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.  
  1649.  
  1650.  
  1651.   +=============================================================================+
  1652.   |           D - DIRECT ACCESS DEVICE                                          |
  1653.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1654.   |           . L - PRINTER DEVICE                                              |
  1655.   |           .  P - PROCESSOR DEVICE                                           |
  1656.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1657.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1658.   |           .  .  S - SCANNER DEVICE                                          |
  1659.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1660.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1661.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1662.   |           .  .  .  .                                                        |
  1663.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1664.   | --- ----              ----------------------------------------------------- |
  1665.   | 13h  00h  D   W  O    ADDRESS MARK NOT FOUND FOR DATA FIELD                 |
  1666.   | 12h  00h  D   W  O    ADDRESS MARK NOT FOUND FOR ID FIELD                   |
  1667.   | 00h  11h       R      AUDIO PLAY OPERATION IN PROGRESS                      |
  1668.   | 00h  12h       R      AUDIO PLAY OPERATION PAUSED                           |
  1669.   | 00h  14h       R      AUDIO PLAY OPERATION STOPPED DUE TO ERROR             |
  1670.   | 00h  13h       R      AUDIO PLAY OPERATION SUCCESSFULLY COMPLETED           |
  1671.   | 00h  04h   T    S     BEGINNING-OF-PARTITION/MEDIUM DETECTED                |
  1672.   | 14h  04h   T          BLOCK SEQUENCE ERROR                                  |
  1673.   | 30h  02h  DT  WR O    CANNOT READ MEDIUM - INCOMPATIBLE FORMAT              |
  1674.   | 30h  01h  DT  WR O    CANNOT READ MEDIUM - UNKNOWN FORMAT                   |
  1675.   | 52h  00h   T          CARTRIDGE FAULT                                       |
  1676.   | 3Fh  02h  DTLPWRSOMC  CHANGED OPERATING DEFINITION                          |
  1677.   | 11h  06h      WR O    CIRC UNRECOVERED ERROR                                |
  1678.   | 30h  03h  DT          CLEANING CARTRIDGE INSTALLED                          |
  1679.   | 4Ah  00h  DTLPWRSOMC  COMMAND PHASE ERROR                                   |
  1680.   | 2Ch  00h  DTLPWRSOMC  COMMAND SEQUENCE ERROR                                |
  1681.   | 2Fh  00h  DTLPWRSOMC  COMMANDS CLEARED BY ANOTHER INITIATOR                 |
  1682.   | 2Bh  00h  DTLPWRSO C  COPY CANNOT EXECUTE SINCE HOST CANNOT DISCONNECT      |
  1683.   | 41h  00h  D           DATA PATH FAILURE (SHOULD USE 40 NN)                  |
  1684.   | 4Bh  00h  DTLPWRSOMC  DATA PHASE ERROR                                      |
  1685.   | 11h  07h      W  O    DATA RESYCHRONIZATION ERROR                           |
  1686.   | 16h  00h  D   W  O    DATA SYNCHRONIZATION MARK ERROR                       |
  1687.   | 19h  00h  D      O    DEFECT LIST ERROR                                     |
  1688.   | 19h  03h  D      O    DEFECT LIST ERROR IN GROWN LIST                       |
  1689.   | 19h  02h  D      O    DEFECT LIST ERROR IN PRIMARY LIST                     |
  1690.   | 19h  01h  D      O    DEFECT LIST NOT AVAILABLE                             |
  1691.   | 1Ch  00h  D      O    DEFECT LIST NOT FOUND                                 |
  1692.   | 32h  01h  D   W  O    DEFECT LIST UPDATE FAILURE                            |
  1693.   | 40h  NNh  DTLPWRSOMC  DIAGNOSTIC FAILURE ON COMPONENT NN (80H-FFH)          |
  1694.   | 63h  00h       R      END OF USER AREA ENCOUNTERED ON THIS TRACK            |
  1695.   | 00h  05h   T    S     END-OF-DATA DETECTED                                  |
  1696.   | 14h  03h   T          END-OF-DATA NOT FOUND                                 |
  1697.   | 00h  02h   T    S     END-OF-PARTITION/MEDIUM DETECTED                      |
  1698.   | 51h  00h   T     O    ERASE FAILURE                                         |
  1699.   | 0Ah  00h  DTLPWRSOMC  ERROR LOG OVERFLOW                                    |
  1700.   | 11h  02h  DT  W SO    ERROR TOO LONG TO CORRECT                             |
  1701.   | 03h  02h   T          EXCESSIVE WRITE ERRORS                                |
  1702.   | 3Bh  07h    L         FAILED TO SENSE BOTTOM-OF-FORM                        |
  1703.   | 3Bh  06h    L         FAILED TO SENSE TOP-OF-FORM                           |
  1704.   | 00h  01h   T          FILEMARK DETECTED                                     |
  1705.   | 14h  02h   T          FILEMARK OR SETMARK NOT FOUND                         |
  1706.   | 09h  02h      WR O    FOCUS SERVO FAILURE                                   |
  1707.   | 31h  01h  D L    O    FORMAT COMMAND FAILED                                 |
  1708.   | 58h  00h         O    GENERATION DOES NOT EXIST                             |
  1709.   +=============================================================================+
  1710.  
  1711.  
  1712.  
  1713.  
  1714.  
  1715.  
  1716.  
  1717.   Table 71: (continued)
  1718.   +=============================================================================+
  1719.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1720.   | --- ----              ----------------------------------------------------- |
  1721.   | 1Ch  02h  D      O    GROWN DEFECT LIST NOT FOUND                           |
  1722.   | 00h  06h  DTLPWRSOMC  I/O PROCESS TERMINATED                                |
  1723.   | 10h  00h  D   W  O    ID CRC OR ECC ERROR                                   |
  1724.   | 22h  00h  D           ILLEGAL FUNCTION (SHOULD USE 20 00, 24 00, OR 26 00)  |
  1725.   | 64h  00h       R      ILLEGAL MODE FOR THIS TRACK                           |
  1726.   | 28h  01h          M   IMPORT OR EXPORT ELEMENT ACCESSED                     |
  1727.   | 30h  00h  DT  WR OM   INCOMPATIBLE MEDIUM INSTALLED                         |
  1728.   | 11h  08h   T          INCOMPLETE BLOCK READ                                 |
  1729.   | 48h  00h  DTLPWRSOMC  INITIATOR DETECTED ERROR MESSAGE RECEIVED             |
  1730.   | 3Fh  03h  DTLPWRSOMC  INQUIRY DATA HAS CHANGED                              |
  1731.   | 44h  00h  DTLPWRSOMC  INTERNAL TARGET FAILURE                               |
  1732.   | 3Dh  00h  DTLPWRSOMC  INVALID BITS IN IDENTIFY MESSAGE                      |
  1733.   | 2Ch  02h        S     INVALID COMBINATION OF WINDOWS SPECIFIED              |
  1734.   | 20h  00h  DTLPWRSOMC  INVALID COMMAND OPERATION CODE                        |
  1735.   | 21h  01h          M   INVALID ELEMENT ADDRESS                               |
  1736.   | 24h  00h  DTLPWRSOMC  INVALID FIELD IN CDB                                  |
  1737.   | 26h  00h  DTLPWRSOMC  INVALID FIELD IN PARAMETER LIST                       |
  1738.   | 49h  00h  DTLPWRSOMC  INVALID MESSAGE ERROR                                 |
  1739.   | 11h  05h      WR O    L-EC UNCORRECTABLE ERROR                              |
  1740.   | 60h  00h        S     LAMP FAILURE                                          |
  1741.   | 5Bh  02h  DTLPWRSOM   LOG COUNTER AT MAXIMUM                                |
  1742.   | 5Bh  00h  DTLPWRSOM   LOG EXCEPTION                                         |
  1743.   | 5Bh  03h  DTLPWRSOM   LOG LIST CODES EXHAUSTED                              |
  1744.   | 2Ah  02h  DTL WRSOMC  LOG PARAMETERS CHANGED                                |
  1745.   | 21h  00h  DT  WR OM   LOGICAL BLOCK ADDRESS OUT OF RANGE                    |
  1746.   | 08h  00h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION FAILURE                    |
  1747.   | 08h  02h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION PARITY ERROR               |
  1748.   | 08h  01h  DTL WRSOMC  LOGICAL UNIT COMMUNICATION TIME-OUT                   |
  1749.   | 4Ch  00h  DTLPWRSOMC  LOGICAL UNIT FAILED SELF-CONFIGURATION                |
  1750.   | 3Eh  00h  DTLPWRSOMC  LOGICAL UNIT HAS NOT SELF-CONFIGURED YET              |
  1751.   | 04h  01h  DTLPWRSOMC  LOGICAL UNIT IS IN PROCESS OF BECOMING READY          |
  1752.   | 04h  00h  DTLPWRSOMC  LOGICAL UNIT NOT READY, CAUSE NOT REPORTABLE          |
  1753.   | 04h  04h  DTL    O    LOGICAL UNIT NOT READY, FORMAT IN PROGRESS            |
  1754.   | 04h  02h  DTLPWRSOMC  LOGICAL UNIT NOT READY, INITIALIZING COMMAND REQUIRED |
  1755.   | 04h  03h  DTLPWRSOMC  LOGICAL UNIT NOT READY, MANUAL INTERVENTION REQUIRED  |
  1756.   | 25h  00h  DTLPWRSOMC  LOGICAL UNIT NOT SUPPORTED                            |
  1757.   | 15h  01h  DTL WRSOM   MECHANICAL POSITIONING ERROR                          |
  1758.   | 53h  00h  DTL WRSOM   MEDIA LOAD OR EJECT FAILED                            |
  1759.   | 3Bh  0Dh          M   MEDIUM DESTINATION ELEMENT FULL                       |
  1760.   | 31h  00h  DT  W  O    MEDIUM FORMAT CORRUPTED                               |
  1761.   | 3Ah  00h  DTL WRSOM   MEDIUM NOT PRESENT                                    |
  1762.   | 53h  02h  DT  WR OM   MEDIUM REMOVAL PREVENTED                              |
  1763.   | 3Bh  0Eh          M   MEDIUM SOURCE ELEMENT EMPTY                           |
  1764.   | 43h  00h  DTLPWRSOMC  MESSAGE ERROR                                         |
  1765.   | 3Fh  01h  DTLPWRSOMC  MICROCODE HAS BEEN CHANGED                            |
  1766.   | 1Dh  00h  D   W  O    MISCOMPARE DURING VERIFY OPERATION                    |
  1767.   | 11h  0Ah  DT     O    MISCORRECTED ERROR                                    |
  1768.   | 2Ah  01h  DTL WRSOMC  MODE PARAMETERS CHANGED                               |
  1769.   | 07h  00h  DTL WRSOM   MULTIPLE PERIPHERAL DEVICES SELECTED                  |
  1770.   | 11h  03h  DT  W SO    MULTIPLE READ ERRORS                                  |
  1771.   | 00h  00h  DTLPWRSOMC  NO ADDITIONAL SENSE INFORMATION                       |
  1772.   | 00h  15h       R      NO CURRENT AUDIO STATUS TO RETURN                     |
  1773.   | 32h  00h  D   W  O    NO DEFECT SPARE LOCATION AVAILABLE                    |
  1774.   | 11h  09h   T          NO GAP FOUND                                          |
  1775.   | 01h  00h  D   W  O    NO INDEX/SECTOR SIGNAL                                |
  1776.   | 06h  00h  D   WR OM   NO REFERENCE POSITION FOUND                           |
  1777.   +=============================================================================+
  1778.  
  1779.  
  1780.  
  1781.  
  1782.  
  1783.        Table 71: (continued)
  1784.        +=============================================================================+
  1785.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1786.        | --- ----              ----------------------------------------------------- |
  1787.        | 02h  00h  D   WR OM   NO SEEK COMPLETE                                      |
  1788.        | 03h  01h   T          NO WRITE CURRENT                                      |
  1789.        | 28h  00h  DTLPWRSOMC  NOT READY TO READY TRANSITION, MEDIUM MAY HAVE CHANGED|
  1790.        | 5Ah  01h  DT  WR OM   OPERATOR MEDIUM REMOVAL REQUEST                       |
  1791.        | 5Ah  00h  DTLPWRSOM   OPERATOR REQUEST OR STATE CHANGE INPUT (UNSPECIFIED)  |
  1792.        | 5Ah  03h  DT  W  O    OPERATOR SELECTED WRITE PERMIT                        |
  1793.        | 5Ah  02h  DT  W  O    OPERATOR SELECTED WRITE PROTECT                       |
  1794.        | 61h  02h        S     OUT OF FOCUS                                          |
  1795.        | 4Eh  00h  DTLPWRSOMC  OVERLAPPED COMMANDS ATTEMPTED                         |
  1796.        | 2Dh  00h   T          OVERWRITE ERROR ON UPDATE IN PLACE                    |
  1797.        | 3Bh  05h    L         PAPER JAM                                             |
  1798.        | 1Ah  00h  DTLPWRSOMC  PARAMETER LIST LENGTH ERROR                           |
  1799.        | 26h  01h  DTLPWRSOMC  PARAMETER NOT SUPPORTED                               |
  1800.        | 26h  02h  DTLPWRSOMC  PARAMETER VALUE INVALID                               |
  1801.        | 2Ah  00h  DTL WRSOMC  PARAMETERS CHANGED                                    |
  1802.        | 03h  00h  DTL W SO    PERIPHERAL DEVICE WRITE FAULT                         |
  1803.        | 50h  02h   T          POSITION ERROR RELATED TO TIMING                      |
  1804.        | 3Bh  0Ch        S     POSITION PAST BEGINNING OF MEDIUM                     |
  1805.        | 3Bh  0Bh        S     POSITION PAST END OF MEDIUM                           |
  1806.        | 15h  02h  DT  WR O    POSITIONING ERROR DETECTED BY READ OF MEDIUM          |
  1807.        | 29h  00h  DTLPWRSOMC  POWER ON, RESET, OR BUS DEVICE RESET OCCURRED         |
  1808.        | 42h  00h  D           POWER-ON OR SELF-TEST FAILURE (SHOULD USE 40 NN)      |
  1809.        | 1Ch  01h  D      O    PRIMARY DEFECT LIST NOT FOUND                         |
  1810.        | 40h  00h  D           RAM FAILURE (SHOULD USE 40 NN)                        |
  1811.        | 15h  00h  DTL WRSOM   RANDOM POSITIONING ERROR                              |
  1812.        | 3Bh  0Ah        S     READ PAST BEGINNING OF MEDIUM                         |
  1813.        | 3Bh  09h        S     READ PAST END OF MEDIUM                               |
  1814.        | 11h  01h  DT  W SO    READ RETRIES EXHAUSTED                                |
  1815.        | 14h  01h  DT  WR O    RECORD NOT FOUND                                      |
  1816.        | 14h  00h  DTL WRSO    RECORDED ENTITY NOT FOUND                             |
  1817.        | 18h  02h  D   WR O    RECOVERED DATA - DATA AUTO-REALLOCATED                |
  1818.        | 18h  05h  D   WR O    RECOVERED DATA - RECOMMEND REASSIGNMENT               |
  1819.        | 18h  06h  D   WR O    RECOVERED DATA - RECOMMEND REWRITE                    |
  1820.        | 17h  05h  D   WR O    RECOVERED DATA USING PREVIOUS SECTOR ID               |
  1821.        | 18h  03h       R      RECOVERED DATA WITH CIRC                              |
  1822.        | 18h  01h  D   WR O    RECOVERED DATA WITH ERROR CORRECTION & RETRIES APPLIED|
  1823.        | 18h  00h  DT  WR O    RECOVERED DATA WITH ERROR CORRECTION APPLIED          |
  1824.        | 18h  04h       R      RECOVERED DATA WITH L-EC                              |
  1825.        | 17h  03h  DT  WR O    RECOVERED DATA WITH NEGATIVE HEAD OFFSET              |
  1826.        | 17h  00h  DT  WRSO    RECOVERED DATA WITH NO ERROR CORRECTION APPLIED       |
  1827.        | 17h  02h  DT  WR O    RECOVERED DATA WITH POSITIVE HEAD OFFSET              |
  1828.        | 17h  01h  DT  WRSO    RECOVERED DATA WITH RETRIES                           |
  1829.        | 17h  04h      WR O    RECOVERED DATA WITH RETRIES AND/OR CIRC APPLIED       |
  1830.        | 17h  06h  D   W  O    RECOVERED DATA WITHOUT ECC - DATA AUTO-REALLOCATED    |
  1831.        | 17h  07h  D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REASSIGNMENT   |
  1832.        | 17h  08h  D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REWRITE        |
  1833.        | 1Eh  00h  D   W  O    RECOVERED ID WITH ECC CORRECTION                      |
  1834.        | 3Bh  08h   T          REPOSITION ERROR                                      |
  1835.        | 36h  00h    L         RIBBON, INK, OR TONER FAILURE                         |
  1836.        | 37h  00h  DTL WRSOMC  ROUNDED PARAMETER                                     |
  1837.        | 5Ch  00h  D      O    RPL STATUS CHANGE                                     |
  1838.        | 39h  00h  DTL WRSOMC  SAVING PARAMETERS NOT SUPPORTED                       |
  1839.        | 62h  00h        S     SCAN HEAD POSITIONING ERROR                           |
  1840.        | 47h  00h  DTLPWRSOMC  SCSI PARITY ERROR                                     |
  1841.        | 54h  00h     P        SCSI TO HOST SYSTEM INTERFACE FAILURE                 |
  1842.        | 45h  00h  DTLPWRSOMC  SELECT OR RESELECT FAILURE                            |
  1843.        +=============================================================================+
  1844.  
  1845.  
  1846.  
  1847.  
  1848.  
  1849.        Table 71: (concluded)
  1850.        +=============================================================================+
  1851.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1852.        | --- ----              ----------------------------------------------------- |
  1853.        | 3Bh  00h   TL         SEQUENTIAL POSITIONING ERROR                          |
  1854.        | 00h  03h   T          SETMARK DETECTED                                      |
  1855.        | 3Bh  04h    L         SLEW FAILURE                                          |
  1856.        | 09h  03h      WR O    SPINDLE SERVO FAILURE                                 |
  1857.        | 5Ch  02h  D      O    SPINDLES NOT SYNCHRONIZED                             |
  1858.        | 5Ch  01h  D      O    SPINDLES SYNCHRONIZED                                 |
  1859.        | 1Bh  00h  DTLPWRSOMC  SYNCHRONOUS DATA TRANSFER ERROR                       |
  1860.        | 55h  00h     P        SYSTEM RESOURCE FAILURE                               |
  1861.        | 33h  00h   T          TAPE LENGTH ERROR                                     |
  1862.        | 3Bh  03h    L         TAPE OR ELECTRONIC VERTICAL FORMS UNIT NOT READY      |
  1863.        | 3Bh  01h   T          TAPE POSITION ERROR AT BEGINNING-OF-MEDIUM            |
  1864.        | 3Bh  02h   T          TAPE POSITION ERROR AT END-OF-MEDIUM                  |
  1865.        | 3Fh  00h  DTLPWRSOMC  TARGET OPERATING CONDITIONS HAVE CHANGED              |
  1866.        | 5Bh  01h  DTLPWRSOM   THRESHOLD CONDITION MET                               |
  1867.        | 26h  03h  DTLPWRSOMC  THRESHOLD PARAMETERS NOT SUPPORTED                    |
  1868.        | 2Ch  01h        S     TOO MANY WINDOWS SPECIFIED                            |
  1869.        | 09h  00h  DT  WR O    TRACK FOLLOWING ERROR                                 |
  1870.        | 09h  01h      WR O    TRACKING SERVO FAILURE                                |
  1871.        | 61h  01h        S     UNABLE TO ACQUIRE VIDEO                               |
  1872.        | 57h  00h       R      UNABLE TO RECOVER TABLE-OF-CONTENTS                   |
  1873.        | 53h  01h   T          UNLOAD TAPE FAILURE                                   |
  1874.        | 11h  00h  DT  WRSO    UNRECOVERED READ ERROR                                |
  1875.        | 11h  04h  D   W  O    UNRECOVERED READ ERROR - AUTO REALLOCATE FAILED       |
  1876.        | 11h  0Bh  D   W  O    UNRECOVERED READ ERROR - RECOMMEND REASSIGNMENT       |
  1877.        | 11h  0Ch  D   W  O    UNRECOVERED READ ERROR - RECOMMEND REWRITE THE DATA   |
  1878.        | 46h  00h  DTLPWRSOMC  UNSUCCESSFUL SOFT RESET                               |
  1879.        | 59h  00h         O    UPDATED BLOCK READ                                    |
  1880.        | 61h  00h        S     VIDEO ACQUISITION ERROR                               |
  1881.        | 50h  00h   T          WRITE APPEND ERROR                                    |
  1882.        | 50h  01h   T          WRITE APPEND POSITION ERROR                           |
  1883.        | 0Ch  00h   T    S     WRITE ERROR                                           |
  1884.        | 0Ch  02h  D   W  O    WRITE ERROR - AUTO REALLOCATION FAILED                |
  1885.        | 0Ch  01h  D   W  O    WRITE ERROR RECOVERED WITH AUTO REALLOCATION          |
  1886.        | 27h  00h  DT  W  O    WRITE PROTECTED                                       |
  1887.        |                                                                             |
  1888.        | 80h  XXh     \                                                              |
  1889.        | THROUGH       >       VENDOR SPECIFIC.                                      |
  1890.        | FFh  XX      /                                                              |
  1891.        |                                                                             |
  1892.        | XXh  80h     \                                                              |
  1893.        | THROUGH       >       VENDOR SPECIFIC QUALIFICATION OF STANDARD ASC.        |
  1894.        | XXh  FFh     /                                                              |
  1895.        |                       ALL CODES NOT SHOWN ARE RESERVED.                     |
  1896.        |-----------------------------------------------------------------------------|
  1897.  
  1898.  
  1899.  
  1900.  
  1901.  
  1902.  
  1903.   U.2.  ASC and ASCQ in numerical order
  1904.  
  1905.  
  1906.  
  1907.  
  1908.  
  1909.  
  1910.  
  1911.  
  1912.  
  1913.  
  1914.  
  1915.                          Table 364: ASC and ASCQ Assignments
  1916.  
  1917.   +=============================================================================+
  1918.   |           D - DIRECT ACCESS DEVICE                                          |
  1919.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1920.   |           . L - PRINTER DEVICE                                              |
  1921.   |           .  P - PROCESSOR DEVICE                                           |
  1922.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1923.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1924.   |           .  .  S - SCANNER DEVICE                                          |
  1925.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1926.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1927.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1928.   |           .  .  .  .                                                        |
  1929.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1930.   | --- ----              ----------------------------------------------------- |
  1931.   |  00  00   DTLPWRSOMC  NO ADDITIONAL SENSE INFORMATION                       |
  1932.   |  00  01    T          FILEMARK DETECTED                                     |
  1933.   |  00  02    T    S     END-OF-PARTITION/MEDIUM DETECTED                      |
  1934.   |  00  03    T          SETMARK DETECTED                                      |
  1935.   |  00  04    T    S     BEGINNING-OF-PARTITION/MEDIUM DETECTED                |
  1936.   |  00  05    T    S     END-OF-DATA DETECTED                                  |
  1937.   |  00  06   DTLPWRSOMC  I/O PROCESS TERMINATED                                |
  1938.   |  00  11   R           AUDIO PLAY OPERATION IN PROGRESS                      |
  1939.   |  00  12   R           AUDIO PLAY OPERATION PAUSED                           |
  1940.   |  00  13   R           AUDIO PLAY OPERATION SUCCESSFULLY COMPLETED           |
  1941.   |  00  14   R           AUDIO PLAY OPERATION STOPPED DUE TO ERROR             |
  1942.   |  00  15   R           NO CURRENT AUDIO STATUS TO RETURN                     |
  1943.   |  01  00   DW  O       NO INDEX/SECTOR SIGNAL                                |
  1944.   |  02  00   DWR OM      NO SEEK COMPLETE                                      |
  1945.   |  03  00   DTL W SO    PERIPHERAL DEVICE WRITE FAULT                         |
  1946.   |  03  01    T          NO WRITE CURRENT                                      |
  1947.   |  03  02    T          EXCESSIVE WRITE ERRORS                                |
  1948.   |  04  00   DTLPWRSOMC  LOGICAL UNIT NOT READY, CAUSE NOT REPORTABLE          |
  1949.   |  04  01   DTLPWRSOMC  LOGICAL UNIT IS IN PROCESS OF BECOMING READY          |
  1950.   |  04  02   DTLPWRSOMC  LOGICAL UNIT NOT READY, INITIALIZING COMMAND REQUIRED |
  1951.   |  04  03   DTLPWRSOMC  LOGICAL UNIT NOT READY, MANUAL INTERVENTION REQUIRED  |
  1952.   |  04  04   DTL    O    LOGICAL UNIT NOT READY, FORMAT IN PROGRESS            |
  1953.   |  05  00   DTL WRSOMC  LOGICAL UNIT DOES NOT RESPOND TO SELECTION            |
  1954.   |  06  00   DWR OM  NO  REFERENCE POSITION FOUND                              |
  1955.   |  07  00   DTL WRSOM   MULTIPLE PERIPHERAL DEVICES SELECTED                  |
  1956.   |  08  00   DTL WRSOMC  LOGICAL UNIT COMMUNICATION FAILURE                    |
  1957.   |  08  01   DTL WRSOMC  LOGICAL UNIT COMMUNICATION TIME-OUT                   |
  1958.   |  08  02   DTL WRSOMC  LOGICAL UNIT COMMUNICATION PARITY ERROR               |
  1959.   |  09  00   DT  WR O    TRACK FOLLOWING ERROR                                 |
  1960.   |  09  01       WR O    TRA CKING SERVO FAILURE                               |
  1961.   |  09  02       WR O    FOC US SERVO FAILURE                                  |
  1962.   |  09  03       WR O    SPI NDLE SERVO FAILURE                                |
  1963.   +=============================================================================+
  1964.  
  1965.  
  1966.  
  1967.  
  1968.  
  1969.  
  1970.  
  1971.  
  1972.  
  1973.  
  1974.  
  1975.  
  1976.  
  1977.  
  1978.  
  1979.  
  1980.  
  1981.   Table 364: (continued)
  1982.   +=============================================================================+
  1983.   |           D - DIRECT ACCESS DEVICE                                          |
  1984.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  1985.   |           . L - PRINTER DEVICE                                              |
  1986.   |           .  P - PROCESSOR DEVICE                                           |
  1987.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  1988.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  1989.   |           .  .  S - SCANNER DEVICE                                          |
  1990.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  1991.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  1992.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  1993.   |           .  .  .  .                                                        |
  1994.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  1995.   | --- ----              ----------------------------------------------------- |
  1996.   |  0A  00   DTLPWRSOMC  ERROR LOG OVERFLOW                                    |
  1997.   |  0B  00                                                                     |
  1998.   |  0C  00    T     S    WRITE ERROR                                           |
  1999.   |  0C  01   D   W  O    WRITE ERROR RECOVERED WITH AUTO REALLOCATION          |
  2000.   |  0C  02   D   W  O    WRITE ERROR - AUTO REALLOCATION FAILED                |
  2001.   |  0D  00                                                                     |
  2002.   |  0E  00                                                                     |
  2003.   |  0F  00                                                                     |
  2004.   |  10  00   D   W  O    ID CRC OR ECC ERROR                                   |
  2005.   |  11  00   DT  WRSO    UNRECOVERED READ ERROR                                |
  2006.   |  11  01   DT  W SO    READ RETRIES EXHAUSTED                                |
  2007.   |  11  02   DT  W SO    ERROR TOO LONG TO CORRECT                             |
  2008.   |  11  03   DT  W SO    MULTIPLE READ ERRORS                                  |
  2009.   |  11  04   D   W  O    UNRECOVERED READ ERROR - AUTO REALLOCATE FAILED       |
  2010.   |  11  05       WR O    L-EC UNCORRECTABLE ERROR                              |
  2011.   |  11  06       WR O    CIRC UNRECOVERED ERROR                                |
  2012.   |  11  07       W  O    DATA RESYCHRONIZATION ERROR                           |
  2013.   |  11  08    T          INCOMPLETE BLOCK READ                                 |
  2014.   |  11  09    T          NO GAP FOUND                                          |
  2015.   |  11  0A   DT     O    MISCORRECTED ERROR                                    |
  2016.   |  11  0B   D   W  O    UNRECOVERED READ ERROR - RECOMMEND REASSIGNMENT       |
  2017.   |  11  0C   D   W  O    UNRECOVERED READ ERROR - RECOMMEND REWRITE THE DATA   |
  2018.   |  12  00   D   W  O    ADDRESS MARK NOT FOUND FOR ID FIELD                   |
  2019.   |  13  00   D   W  O    ADDRESS MARK NOT FOUND FOR DATA FIELD                 |
  2020.   |  14  00   DTL WRSO    RECORDED ENTITY NOT FOUND                             |
  2021.   |  14  01   DT  WR O    RECORD NOT FOUND                                      |
  2022.   |  14  02    T          FILEMARK OR SETMARK NOT FOUND                         |
  2023.   |  14  03    T          END-OF-DATA NOT FOUND                                 |
  2024.   |  14  04    T          BLOCK SEQUENCE ERROR                                  |
  2025.   |  15  00   DTL WRSOM   RANDOM POSITIONING ERROR                              |
  2026.   |  15  01   DTL WRSOM   MECHANICAL POSITIONING ERROR                          |
  2027.   |  15  02   DT  WR O    POSITIONING ERROR DETECTED BY READ OF MEDIUM          |
  2028.   |  16  00   DW     O    DATA SYNCHRONIZATION MARK ERROR                       |
  2029.   |  17  00   DT  WRSO    RECOVERED DATA WITH NO ERROR CORRECTION APPLIED       |
  2030.   |  17  01   DT  WRSO    RECOVERED DATA WITH RETRIES                           |
  2031.   |  17  02   DT  WR O    RECOVERED DATA WITH POSITIVE HEAD OFFSET              |
  2032.   |  17  03   DT  WR O    RECOVERED DATA WITH NEGATIVE HEAD OFFSET              |
  2033.   |  17  04       WR O    RECOVERED DATA WITH RETRIES AND/OR CIRC APPLIED       |
  2034.   |  17  05   D   WR O    RECOVERED DATA USING PREVIOUS SECTOR ID               |
  2035.   |  17  06   D   W  O    RECOVERED DATA WITHOUT ECC - DATA AUTO-REALLOCATED    |
  2036.   |  17  07   D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REASSIGNMENT   |
  2037.   |  17  08   D   W  O    RECOVERED DATA WITHOUT ECC - RECOMMEND REWRITE        |
  2038.   |  18  00   DT  WR O    RECOVERED DATA WITH ERROR CORRECTION APPLIED          |
  2039.   |  18  01   D   WR O    RECOVERED DATA WITH ERROR CORRECTION & RETRIES APPLIED|
  2040.   |  18  02   D   WR O    RECOVERED DATA - DATA AUTO-REALLOCATED                |
  2041.   |  18  03        R      RECOVERED DATA WITH CIRC                              |
  2042.   |  18  04        R      RECOVERED DATA WITH LEC                               |
  2043.   |  18  05   D   WR O    RECOVERED DATA - RECOMMEND REASSIGNMENT               |
  2044.   |  18  06   D   WR O    RECOVERED DATA - RECOMMEND REWRITE                    |
  2045.   +=============================================================================+
  2046.  
  2047.        Table 364: (continued)
  2048.        +=============================================================================+
  2049.        |           D - DIRECT ACCESS DEVICE                                          |
  2050.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  2051.        |           . L - PRINTER DEVICE                                              |
  2052.        |           .  P - PROCESSOR DEVICE                                           |
  2053.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  2054.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2055.        |           .  .  S - SCANNER DEVICE                                          |
  2056.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2057.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2058.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2059.        |           .  .  .  .                                                        |
  2060.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  2061.        | --- ----              ----------------------------------------------------- |
  2062.        |  19  00   D      O    DEFECT LIST ERROR                                     |
  2063.        |  19  01   D      O    DEFECT LIST NOT AVAILABLE                             |
  2064.        |  19  02   D      O    DEFECT LIST ERROR IN PRIMARY LIST                     |
  2065.        |  19  03   D      O    DEFECT LIST ERROR IN GROWN LIST                       |
  2066.        |  1A  00   DTLPWRSOMC  PARAMETER LIST LENGTH ERROR                           |
  2067.        |  1B  00   DTLPWRSOMC  SYNCHRONOUS DATA TRANSFER ERROR                       |
  2068.        |  1C  00   D      O    DEFECT LIST NOT FOUND                                 |
  2069.        |  1C  01   D      O    PRIMARY DEFECT LIST NOT FOUND                         |
  2070.        |  1C  02   D      O    GROWN DEFECT LIST NOT FOUND                           |
  2071.        |  1D  00   D   W  O    MISCOMPARE DURING VERIFY OPERATION                    |
  2072.        |  1E  00   D   W  O    RECOVERED ID WITH ECC                                 |
  2073.        |  1F  00                                                                     |
  2074.        |  20  00   DTLPWRSOMC  INVALID COMMAND OPERATION CODE                        |
  2075.        |  21  00   DT  WR OM   LOGICAL BLOCK ADDRESS OUT OF RANGE                    |
  2076.        |  21  01           M   INVALID ELEMENT ADDRESS                               |
  2077.        |  22  00   D           ILLEGAL FUNCTION (SHOULD USE 20 00, 24 00, OR 26 00)  |
  2078.        |  23  00                                                                     |
  2079.        |  24  00   DTLPWRSOMC  INVALID FIELD IN CDB                                  |
  2080.        |  25  00   DTLPWRSOMC  LOGICAL UNIT NOT SUPPORTED                            |
  2081.        |  26  00   DTLPWRSOMC  INVALID FIELD IN PARAMETER LIST                       |
  2082.        |  26  01   DTLPWRSOMC  PARAMETER NOT SUPPORTED                               |
  2083.        |  26  02   DTLPWRSOMC  PARAMETER VALUE INVALID                               |
  2084.        |  26  03   DTLPWRSOMC  THRESHOLD PARAMETERS NOT SUPPORTED                    |
  2085.        |  27  00   DT  W  O    WRITE PROTECTED                                       |
  2086.        |  28  00   DTLPWRSOMC  NOT READY TO READY TRANSITION(MEDIUM MAY HAVE CHANGED)|
  2087.        |  28  01           M   IMPORT OR EXPORT ELEMENT ACCESSED                     |
  2088.        |  29  00   DTLPWRSOMC  POWER ON, RESET, OR BUS DEVICE RESET OCCURRED         |
  2089.        |  2A  00   DTL WRSOMC  PARAMETERS CHANGED                                    |
  2090.        |  2A  01   DTL WRSOMC  MODE PARAMETERS CHANGED                               |
  2091.        |  2A  02   DTL WRSOMC  LOG PARAMETERS CHANGED                                |
  2092.        |  2B  00   DTLPWRSO C  COPY CANNOT EXECUTE SINCE HOST CANNOT DISCONNECT      |
  2093.        |  2C  00   DTLPWRSOMC  COMMAND SEQUENCE ERROR                                |
  2094.        |  2C  01         S     TOO MANY WINDOWS SPECIFIED                            |
  2095.        |  2C  02         S     INVALID COMBINATION OF WINDOWS SPECIFIED              |
  2096.        |  2D  00    T          OVERWRITE ERROR ON UPDATE IN PLACE                    |
  2097.        |  2E  00                                                                     |
  2098.        |  2F  00   DTLPWRSOMC  COMMANDS CLEARED BY ANOTHER INITIATOR                 |
  2099.        |  30  00   DT  WR OM   INCOMPATIBLE MEDIUM INSTALLED                         |
  2100.        |  30  01   DT  WR O    CANNOT READ MEDIUM - UNKNOWN FORMAT                   |
  2101.        |  30  02   DT  WR O    CANNOT READ MEDIUM - INCOMPATIBLE FORMAT              |
  2102.        |  30  03   DT          CLEANING CARTRIDGE INSTALLED                          |
  2103.        |  31  00   DT  W  O    MEDIUM FORMAT CORRUPTED                               |
  2104.        |  31  01   D L    O    FORMAT COMMAND FAILED                                 |
  2105.        |  32  00   D   W  O    NO DEFECT SPARE LOCATION AVAILABLE                    |
  2106.        |  32  01   D   W  O    DEFECT LIST UPDATE FAILURE                            |
  2107.        |  33  00    T          TAPE LENGTH ERROR                                     |
  2108.        |  34  00                                                                     |
  2109.        |  35  00                                                                     |
  2110.        |  36  00     L         RIBBON, INK, OR TONER FAILURE                         |
  2111.        +=============================================================================+
  2112.  
  2113.        Table 364: (continued)
  2114.        +=============================================================================+
  2115.        |           D - DIRECT ACCESS DEVICE                                          |
  2116.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  2117.        |           . L - PRINTER DEVICE                                              |
  2118.        |           .  P - PROCESSOR DEVICE                                           |
  2119.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  2120.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2121.        |           .  .  S - SCANNER DEVICE                                          |
  2122.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2123.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2124.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2125.        |           .  .  .  .                                                        |
  2126.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  2127.        | --- ----              ----------------------------------------------------- |
  2128.        |  37  00   DTL WRSOMC  ROUNDED PARAMETER                                     |
  2129.        |  38  00                                                                     |
  2130.        |  39  00   DTL WRSOMC  SAVING PARAMETERS NOT SUPPORTED                       |
  2131.        |  3A  00   DTL WRSOM   MEDIUM NOT PRESENT                                    |
  2132.        |  3B  00    TL         SEQUENTIAL POSITIONING ERROR                          |
  2133.        |  3B  01    T          TAPE POSITION ERROR AT BEGINNING-OF-MEDIUM            |
  2134.        |  3B  02    T          TAPE POSITION ERROR AT END-OF-MEDIUM                  |
  2135.        |  3B  03     L         TAPE OR ELECTRONIC VERTICAL FORMS UNIT NOT READY      |
  2136.        |  3B  04     L         SLEW FAILURE                                          |
  2137.        |  3B  05     L         PAPER JAM                                             |
  2138.        |  3B  06     L         FAILED TO SENSE TOP-OF-FORM                           |
  2139.        |  3B  07     L         FAILED TO SENSE BOTTOM-OF-FORM                        |
  2140.        |  3B  08    T          REPOSITION ERROR                                      |
  2141.        |  3B  09         S     READ PAST END OF MEDIUM                               |
  2142.        |  3B  0A         S     READ PAST BEGINNING OF MEDIUM                         |
  2143.        |  3B  0B         S     POSITION PAST END OF MEDIUM                           |
  2144.        |  3B  0C         S     POSITION PAST BEGINNING OF MEDIUM                     |
  2145.        |  3B  0D           M   MEDIUM DESTINATION ELEMENT FULL                       |
  2146.        |  3B  0E           M   MEDIUM SOURCE ELEMENT EMPTY                           |
  2147.        |  3C  00                                                                     |
  2148.        |  3D  00   DTLPWRSOMC  INVALID BITS IN IDENTIFY MESSAGE                      |
  2149.        |  3E  00   DTLPWRSOMC  LOGICAL UNIT HAS NOT SELF-CONFIGURED YET              |
  2150.        |  3F  00   DTLPWRSOMC  TARGET OPERATING CONDITIONS HAVE CHANGED              |
  2151.        |  3F  01   DTLPWRSOMC  MICROCODE HAS BEEN CHANGED                            |
  2152.        |  3F  02   DTLPWRSOMC  CHANGED OPERATING DEFINITION                          |
  2153.        |  3F  03   DTLPWRSOMC  INQUIRY DATA HAS CHANGED                              |
  2154.        |  40  00   D           RAM FAILURE (SHOULD USE 40 NN)                        |
  2155.        |  40  NN   DTLPWRSOMC  DIAGNOSTIC FAILURE ON COMPONENT NN (80H-FFH)          |
  2156.        |  41  00   D           DATA PATH FAILURE (SHOULD USE 40 NN)                  |
  2157.        |  42  00   D           POWER-ON OR SELF-TEST FAILURE (SHOULD USE 40 NN)      |
  2158.        |  43  00   DTLPWRSOMC  MESSAGE ERROR                                         |
  2159.        |  44  00   DTLPWRSOMC  INTERNAL TARGET FAILURE                               |
  2160.        |  45  00   DTLPWRSOMC  SELECT OR RESELECT FAILURE                            |
  2161.        |  46  00   DTLPWRSOMC  UNSUCCESSFUL SOFT RESET                               |
  2162.        |  47  00   DTLPWRSOMC  SCSI PARITY ERROR                                     |
  2163.        |  48  00   DTLPWRSOMC  INITIATOR DETECTED ERROR MESSAGE RECEIVED             |
  2164.        |  49  00   DTLPWRSOMC  INVALID MESSAGE ERROR                                 |
  2165.        |  4A  00   DTLPWRSOMC  COMMAND PHASE ERROR                                   |
  2166.        |  4B  00   DTLPWRSOMC  DATA PHASE ERROR                                      |
  2167.        |  4C  00   DTLPWRSOMC  LOGICAL UNIT FAILED SELF-CONFIGURATION                |
  2168.        |  4D  00                                                                     |
  2169.        |  4E  00   DTLPWRSOMC  OVERLAPPED COMMANDS ATTEMPTED                         |
  2170.        |  4F  00                                                                     |
  2171.        |  50  00    T          WRITE APPEND ERROR                                    |
  2172.        |  50  01    T          WRITE APPEND POSITION ERROR                           |
  2173.        |  50  02    T          POSITION ERROR RELATED TO TIMING                      |
  2174.        |  51  00    T     O    ERASE FAILURE                                         |
  2175.        |  52  00    T          CARTRIDGE FAULT                                       |
  2176.        +=============================================================================+
  2177.  
  2178.  
  2179.        Table 364: (continued)
  2180.        +=============================================================================+
  2181.        |           D - DIRECT ACCESS DEVICE                                          |
  2182.        |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  2183.        |           . L - PRINTER DEVICE                                              |
  2184.        |           .  P - PROCESSOR DEVICE                                           |
  2185.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  2186.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2187.        |           .  .  S - SCANNER DEVICE                                          |
  2188.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2189.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2190.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2191.        |           .  .  .  .                                                        |
  2192.        | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  2193.        | --- ----              ----------------------------------------------------- |
  2194.        |  53  00   DTL WRSOM   MEDIA LOAD OR EJECT FAILED                            |
  2195.        |  53  01    T          UNLOAD TAPE FAILURE                                   |
  2196.        |  53  02   DT  WR OM   MEDIUM REMOVAL PREVENTED                              |
  2197.        |  54  00      P        SCSI TO HOST SYSTEM INTERFACE FAILURE                 |
  2198.        |  55  00      P        SYSTEM RESOURCE FAILURE                               |
  2199.        |  56  00                                                                     |
  2200.        |  57  00        R      UNABLE TO RECOVER TABLE-OF-CONTENTS                   |
  2201.        |  58  00     O         GENERATION DOES NOT EXIST                             |
  2202.        |  59  00     O         UPDATED BLOCK READ                                    |
  2203.        |  5A  00   DTLPWRSOM   OPERATOR REQUEST OR STATE CHANGE INPUT (UNSPECIFIED)  |
  2204.        |  5A  01   DT  WR OM   OPERATOR MEDIUM REMOVAL REQUEST                       |
  2205.        |  5A  02   DT  W  O    OPERATOR SELECTED WRITE PROTECT                       |
  2206.        |  5A  03   DT  W  O    OPERATOR SELECTED WRITE PERMIT                        |
  2207.        |  5B  00   DTLPWRSOM   LOG EXCEPTION                                         |
  2208.        |  5B  01   DTLPWRSOM   THRESHOLD CONDITION MET                               |
  2209.        |  5B  02   DTLPWRSOM   LOG COUNTER AT MAXIMUM                                |
  2210.        |  5B  03   DTLPWRSOM   LOG LIST CODES EXHAUSTED                              |
  2211.        |  5C  00   D   O       RPL STATUS CHANGE                                     |
  2212.        |  5C  01   D   O       SPINDLES SYNCHRONIZED                                 |
  2213.        |  5C  02   D   O       SPINDLES NOT SYNCHRONIZED                             |
  2214.        |  5D  00                                                                     |
  2215.        |  5E  00                                                                     |
  2216.        |  5F  00                                                                     |
  2217.        |  60  00         S     LAMP FAILURE                                          |
  2218.        |  61  00         S     VIDEO ACQUISITION ERROR                               |
  2219.        |  61  01         S     UNABLE TO ACQUIRE VIDEO                               |
  2220.        |  61  02         S     OUT OF FOCUS                                          |
  2221.        |  62  00         S     SCAN HEAD POSITIONING ERROR                           |
  2222.        |  63  00        R      END OF USER AREA ENCOUNTERED ON THIS TRACK            |
  2223.        |  64  00        R      ILLEGAL MODE FOR THIS TRACK                           |
  2224.        |  65  00                                                                     |
  2225.        |  66  00                                                                     |
  2226.        |  67  00                                                                     |
  2227.        |  68  00                                                                     |
  2228.        |  69  00                                                                     |
  2229.        |  6A  00                                                                     |
  2230.        |  6B  00                                                                     |
  2231.        |  6C  00                                                                     |
  2232.        |  6D  00                                                                     |
  2233.        |  6E  00                                                                     |
  2234.        |  6F  00                                                                     |
  2235.        +=============================================================================+
  2236.  
  2237.  
  2238.  
  2239.  
  2240.  
  2241.  
  2242.  
  2243.  
  2244.  
  2245.   Table 364: (concluded)
  2246.   +=============================================================================+
  2247.   |           D - DIRECT ACCESS DEVICE                                          |
  2248.   |           .T - SEQUENTIAL ACCESS DEVICE                                     |
  2249.   |           . L - PRINTER DEVICE                                              |
  2250.   |           .  P - PROCESSOR DEVICE                                           |
  2251.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE                           |
  2252.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2253.   |           .  .  S - SCANNER DEVICE                                          |
  2254.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2255.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2256.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2257.   |           .  .  .  .                                                        |
  2258.   | ASC ASCQ  DTLPWRSOMC  DESCRIPTION                                           |
  2259.   | --- ----              ----------------------------------------------------- |
  2260.   |  70  00                                                                     |
  2261.   |  71  00                                                                     |
  2262.   |  72  00                                                                     |
  2263.   |  73  00                                                                     |
  2264.   |  74  00                                                                     |
  2265.   |  75  00                                                                     |
  2266.   |  76  00                                                                     |
  2267.   |  77  00                                                                     |
  2268.   |  78  00                                                                     |
  2269.   |  79  00                                                                     |
  2270.   |  7A  00                                                                     |
  2271.   |  7B  00                                                                     |
  2272.   |  7C  00                                                                     |
  2273.   |  7D  00                                                                     |
  2274.   |  7E  00                                                                     |
  2275.   |  7F  00                                                                     |
  2276.   |                                                                             |
  2277.   |  80  xxh \                                                                  |
  2278.   |   THROUGH >  VENDOR SPECIFIC.                                               |
  2279.   |  FF  xxh /                                                                  |
  2280.   |                                                                             |
  2281.   |  xxh 80 \                                                                   |
  2282.   |  THROUGH >  VENDOR SPECIFIC QUALIFICATION OF STANDARD ASC.                  |
  2283.   |  xxh FF /                                                                   |
  2284.   |               ALL CODES NOT SHOWN OR BLANK ARE RESERVED.                    |
  2285.   +=============================================================================+
  2286.  
  2287.  
  2288.  
  2289.  
  2290.  
  2291.   V.  A SCSI command code quick reference
  2292.  
  2293.  
  2294.  
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305.  
  2306.  
  2307.  
  2308.  
  2309.  
  2310.  
  2311.   Table 365 is a numerical order listing of the command operation codes.
  2312.  
  2313.                           Table 365: SCSI-2 Operation Codes
  2314.  
  2315.   +=============================================================================+
  2316.   |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  2317.   |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  2318.   |           . L - PRINTER DEVICE                           O = Optional       |
  2319.   |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  2320.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  2321.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2322.   |           .  .  S - SCANNER DEVICE                                          |
  2323.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2324.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2325.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2326.   |           .  .  .  .                                                        |
  2327.   |        OP DTLPWRSOMC Description                                            |
  2328.   |----------+----------+-------------------------------------------------------|
  2329.   |        00 MMMMMMMMMM TEST UNIT READY                                        |
  2330.   |        01  M         REWIND                                                 |
  2331.   |        01 O V OO OO  REZERO UNIT                                            |
  2332.   |        02 VVVVVV  V                                                         |
  2333.   |        03 MMMMMMMMMM REQUEST SENSE                                          |
  2334.   |        04   O        FORMAT                                                 |
  2335.   |        04 M      O   FORMAT UNIT                                            |
  2336.   |        05 VMVVVV  V  READ BLOCK LIMITS                                      |
  2337.   |        06 VVVVVV  V                                                         |
  2338.   |        07         O  INITIALIZE ELEMENT STATUS                              |
  2339.   |        07 OVV O  OV  REASSIGN BLOCKS                                        |
  2340.   |        08          M GET MESSAGE(06)                                        |
  2341.   |        08 OMV OO OV  READ(06)                                               |
  2342.   |        08    O       RECEIVE                                                |
  2343.   |        09 VVVVVV  V                                                         |
  2344.   |        0A   M        PRINT                                                  |
  2345.   |        0A          M SEND MESSAGE(06)                                       |
  2346.   |        0A    M       SEND(06)                                               |
  2347.   |        0A OM  O  OV  WRITE(06)                                              |
  2348.   |        0B O   OO OV  SEEK(06)                                               |
  2349.   |        0B   O        SLEW AND PRINT                                         |
  2350.   |        0C VVVVVV  V                                                         |
  2351.   |        0D VVVVVV  V                                                         |
  2352.   |        0E VVVVVV  V                                                         |
  2353.   |        0F VOVVVV  V  READ REVERSE                                           |
  2354.   |        10   O O      SYNCHRONIZE BUFFER                                     |
  2355.   |        10 VM VVV     WRITE FILEMARKS                                        |
  2356.   |        11 VMVVVV     SPACE                                                  |
  2357.   |        12 MMMMMMMMMM INQUIRY                                                |
  2358.   |        13 VOVVVV     VERIFY(06)                                             |
  2359.   |        14 VOOVVV     RECOVER BUFFERED DATA                                  |
  2360.   |        15 OMO OOOOOO MODE SELECT(06)                                        |
  2361.   |        16 M   MM MO  RESERVE                                                |
  2362.   |        16  MM   M    RESERVE UNIT                                           |
  2363.   |        17 M   MM MO  RELEASE                                                |
  2364.   |        17  MM   M    RELEASE UNIT                                           |
  2365.   |        18 OOOOOOOO   COPY                                                   |
  2366.   |        19 VMVVVV     ERASE                                                  |
  2367.   |        1A OMO OOOOOO MODE SENSE(06)                                         |
  2368.   |        1B  O         LOAD UNLOAD                                            |
  2369.   |        1B       O    SCAN                                                   |
  2370.   |        1B   O        STOP PRINT                                             |
  2371.   |        1B O   OO O   STOP START UNIT                                        |
  2372.   +=============================================================================+
  2373.  
  2374.  
  2375.  
  2376.  
  2377.        Table 365: (continued)
  2378.        +=============================================================================+
  2379.        |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  2380.        |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  2381.        |           . L - PRINTER DEVICE                           O = Optional       |
  2382.        |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  2383.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  2384.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2385.        |           .  .  S - SCANNER DEVICE                                          |
  2386.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2387.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2388.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2389.        |           .  .  .  .                                                        |
  2390.        |        OP DTLPWRSOMC Description                                            |
  2391.        |----------+----------+-------------------------------------------------------|
  2392.        |        1C OOOOOOOOOO RECEIVE DIAGNOSTIC RESULTS                             |
  2393.        |        1D MMMMMMMMMM SEND DIAGNOSTIC                                        |
  2394.        |        1E OO  OO OO  PREVENT ALLOW MEDIUM REMOVAL                           |
  2395.        |        1F                                                                   |
  2396.        |        20 V   VV V                                                          |
  2397.        |        21 V   VV V                                                          |
  2398.        |        22 V   VV V                                                          |
  2399.        |        23 V   VV V                                                          |
  2400.        |        24 V   VVM    SET WINDOW                                             |
  2401.        |        25       O    GET WINDOW                                             |
  2402.        |        25 M   M  M   READ CAPACITY                                          |
  2403.        |        25      M     READ CD-ROM CAPACITY                                   |
  2404.        |        26 V   VV                                                            |
  2405.        |        27 V   VV                                                            |
  2406.        |        28          O GET MESSAGE(10)                                        |
  2407.        |        28 M   MMMM   READ(10)                                               |
  2408.        |        29 V   VV O   READ GENERATION                                        |
  2409.        |        2A          O SEND MESSAGE(10)                                       |
  2410.        |        2A       O    SEND(10)                                               |
  2411.        |        2A M   M  M   WRITE(10)                                              |
  2412.        |        2B  O         LOCATE                                                 |
  2413.        |        2B         O  POSITION TO ELEMENT                                    |
  2414.        |        2B O   OO O   SEEK(10)                                               |
  2415.        |        2C V      O   ERASE(10)                                              |
  2416.        |        2D V   O  O   READ UPDATED BLOCK                                     |
  2417.        |        2E O   O  O   WRITE AND VERIFY(10)                                   |
  2418.        |        2F O   OO O   VERIFY(10)                                             |
  2419.        |        30 O   OO O   SEARCH DATA HIGH(10)                                   |
  2420.        |        31       O    OBJECT POSITION                                        |
  2421.        |        31 O   OO O   SEARCH DATA EQUAL(10)                                  |
  2422.        |        32 O   OO O   SEARCH DATA LOW(10)                                    |
  2423.        |        33 O   OO O   SET LIMITS(10)                                         |
  2424.        |        34       O    GET DATA BUFFER STATUS                                 |
  2425.        |        34 O   OO O   PRE-FETCH                                              |
  2426.        |        34  O         READ POSITION                                          |
  2427.        |        35 O   OO O   SYNCHRONIZE CACHE                                      |
  2428.        |        36 O   OO O   LOCK UNLOCK CACHE                                      |
  2429.        |        37 O      O   READ DEFECT DATA(10)                                   |
  2430.        |        38     O  O   MEDIUM SCAN                                            |
  2431.        |        39 OOOOOOOO   COMPARE                                                |
  2432.        |        3A OOOOOOOO   COPY AND VERIFY                                        |
  2433.        |        3B OOOOOOOOOO WRITE BUFFER                                           |
  2434.        |        3C OOOOOOOOOO READ BUFFER                                            |
  2435.        |        3D     O  O   UPDATE BLOCK                                           |
  2436.        |        3E O   OO O   READ LONG                                              |
  2437.        |        3F O   O  O   WRITE LONG                                             |
  2438.        +=============================================================================+
  2439.  
  2440.  
  2441.  
  2442.  
  2443.        Table 365: (continued)
  2444.        +=============================================================================+
  2445.        |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  2446.        |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  2447.        |           . L - PRINTER DEVICE                           O = Optional       |
  2448.        |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  2449.        |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  2450.        |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2451.        |           .  .  S - SCANNER DEVICE                                          |
  2452.        |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2453.        |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2454.        |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2455.        |           .  .  .  .                                                        |
  2456.        |        OP DTLPWRSOMC Description                                            |
  2457.        |----------+----------+-------------------------------------------------------|
  2458.        |        40 OOOOOOOOOO CHANGE DEFINITION                                      |
  2459.        |        41 O          WRITE SAME                                             |
  2460.        |        42      O     READ SUB-CHANNEL                                       |
  2461.        |        43      O     READ TOC                                               |
  2462.        |        44      O     READ HEADER                                            |
  2463.        |        45      O     PLAY AUDIO(10)                                         |
  2464.        |        46                                                                   |
  2465.        |        47      O     PLAY AUDIO MSF                                         |
  2466.        |        48      O     PLAY AUDIO TRACK INDEX                                 |
  2467.        |        49      O     PLAY TRACK RELATIVE(10)                                |
  2468.        |        4A                                                                   |
  2469.        |        4B      O     PAUSE RESUME                                           |
  2470.        |        4C OOOOOOOOOO LOG SELECT                                             |
  2471.        |        4D OOOOOOOOOO LOG SENSE                                              |
  2472.        |        4E                                                                   |
  2473.        |        4F                                                                   |
  2474.        |        50                                                                   |
  2475.        |        51                                                                   |
  2476.        |        52                                                                   |
  2477.        |        53                                                                   |
  2478.        |        54                                                                   |
  2479.        |        55 OOO OOOOOO MODE SELECT(10)                                        |
  2480.        |        56                                                                   |
  2481.        |        57                                                                   |
  2482.        |        58                                                                   |
  2483.        |        59                                                                   |
  2484.        |        5A OOO OOOOOO MODE SENSE(10)                                         |
  2485.        |        5B                                                                   |
  2486.        |        5C                                                                   |
  2487.        |        5D                                                                   |
  2488.        |        5E                                                                   |
  2489.        |        5F                                                                   |
  2490.        +=============================================================================+
  2491.  
  2492.  
  2493.  
  2494.  
  2495.  
  2496.  
  2497.  
  2498.  
  2499.  
  2500.  
  2501.  
  2502.  
  2503.  
  2504.  
  2505.  
  2506.  
  2507.  
  2508.  
  2509.   Table 365: (concluded)
  2510.   +=============================================================================+
  2511.   |           D - DIRECT ACCESS DEVICE                       Device Column Key  |
  2512.   |           .T - SEQUENTIAL ACCESS DEVICE                  M = Mandatory      |
  2513.   |           . L - PRINTER DEVICE                           O = Optional       |
  2514.   |           .  P - PROCESSOR DEVICE                        V = Vendor Specific|
  2515.   |           .  .W - WRITE ONCE READ MULTIPLE DEVICE        R = Reserved       |
  2516.   |           .  . R - READ ONLY (CD-ROM) DEVICE                                |
  2517.   |           .  .  S - SCANNER DEVICE                                          |
  2518.   |           .  .  .O - OPTICAL MEMORY DEVICE                                  |
  2519.   |           .  .  . M - MEDIA CHANGER DEVICE                                  |
  2520.   |           .  .  .  C - COMMUNICATION DEVICE                                 |
  2521.   |           .  .  .  .                                                        |
  2522.   |        OP DTLPWRSOMC Description                                            |
  2523.   |----------+----------+-------------------------------------------------------|
  2524.   |        A0                                                                   |
  2525.   |        A1                                                                   |
  2526.   |        A2                                                                   |
  2527.   |        A3                                                                   |
  2528.   |        A4                                                                   |
  2529.   |        A5         M  MOVE MEDIUM                                            |
  2530.   |        A5      O     PLAY AUDIO(12)                                         |
  2531.   |        A6         O  EXCHANGE MEDIUM                                        |
  2532.   |        A7                                                                   |
  2533.   |        A8          O GET MESSAGE(12)                                        |
  2534.   |        A8     OO O   READ(12)                                               |
  2535.   |        A9      O     PLAY TRACK RELATIVE(12)                                |
  2536.   |        AA          O SEND MESSAGE(12)                                       |
  2537.   |        AA     O  O   WRITE(12)                                              |
  2538.   |        AB                                                                   |
  2539.   |        AC        O   ERASE(12)                                              |
  2540.   |        AD                                                                   |
  2541.   |        AE     O  O   WRITE AND VERIFY(12)                                   |
  2542.   |        AF     OO O   VERIFY(12)                                             |
  2543.   |        B0     OO O   SEARCH DATA HIGH(12)                                   |
  2544.   |        B1     OO O   SEARCH DATA EQUAL(12)                                  |
  2545.   |        B2     OO O   SEARCH DATA LOW(12)                                    |
  2546.   |        B3     OO O   SET LIMITS(12)                                         |
  2547.   |        B4                                                                   |
  2548.   |        B5                                                                   |
  2549.   |        B5         O  REQUEST VOLUME ELEMENT ADDRESS                         |
  2550.   |        B6                                                                   |
  2551.   |        B6         O  SEND VOLUME TAG                                        |
  2552.   |        B7        O   READ DEFECT DATA(12)                                   |
  2553.   |        B8                                                                   |
  2554.   |        B8         O  READ ELEMENT STATUS                                    |
  2555.   |        B9                                                                   |
  2556.   |        BA                                                                   |
  2557.   |        BB                                                                   |
  2558.   |        BC                                                                   |
  2559.   |        BD                                                                   |
  2560.   |        BE                                                                   |
  2561.   |        BF                                                                   |
  2562.   +=============================================================================+
  2563.  
  2564.  
  2565.  
  2566.  
  2567.  
  2568.   W.  Example programs
  2569.  
  2570.   Here is the C example program, which requests manufacturer/model and
  2571.   reports if a medium is loaded in the device.
  2572.  
  2573.  
  2574.  
  2575.   #define DEVICE "/dev/sgc"
  2576.   /* Example program to demonstrate the generic SCSI interface */
  2577.   #include <stdio.h>
  2578.   #include <unistd.h>
  2579.   #include <string.h>
  2580.   #include <fcntl.h>
  2581.   #include <errno.h>
  2582.   #include <linux/../../drivers/scsi/sg.h>
  2583.  
  2584.   #define DEVICE "/dev/sgc"
  2585.  
  2586.   #define SCSI_OFF sizeof(struct sg_header)
  2587.   static unsigned char cmd[SCSI_OFF + 18];      /* SCSI command buffer */
  2588.   int fd;                               /* SCSI device/file descriptor */
  2589.  
  2590.   /* process a complete scsi cmd. Use the generic scsi interface. */
  2591.   static int handle_scsi_cmd(unsigned cmd_len,         /* command length */
  2592.                              unsigned in_size,         /* input data size */
  2593.                              unsigned char *i_buff,    /* input buffer */
  2594.                              unsigned out_size,        /* output data size */
  2595.                              unsigned char *o_buff     /* output buffer */
  2596.                              )
  2597.   {
  2598.       int status = 0;
  2599.       struct sg_header *sg_hd;
  2600.  
  2601.       /* safety checks */
  2602.       if (!cmd_len) return -1;            /* need a cmd_len != 0 */
  2603.       if (!i_buff) return -1;             /* need an input buffer != NULL */
  2604.   #ifdef SG_BIG_BUFF
  2605.       if (SCSI_OFF + cmd_len + in_size > SG_BIG_BUFF) return -1;
  2606.       if (SCSI_OFF + out_size > SG_BIG_BUFF) return -1;
  2607.   #else
  2608.       if (SCSI_OFF + cmd_len + in_size > 4096) return -1;
  2609.       if (SCSI_OFF + out_size > 4096) return -1;
  2610.   #endif
  2611.  
  2612.       if (!o_buff) out_size = 0;
  2613.  
  2614.       /* generic scsi device header construction */
  2615.       sg_hd = (struct sg_header *) i_buff;
  2616.       sg_hd->reply_len   = SCSI_OFF + out_size;
  2617.       sg_hd->twelve_byte = cmd_len == 12;
  2618.   #if     0
  2619.       sg_hd->pack_len    = SCSI_OFF + cmd_len + in_size; /* not necessary */
  2620.       sg_hd->pack_id;     /* not used */
  2621.       sg_hd->other_flags; /* not used */
  2622.   #endif
  2623.  
  2624.       /* send command */
  2625.       status = write( fd, i_buff, SCSI_OFF + cmd_len + in_size );
  2626.       if ( status < 0 || status != SCSI_OFF + cmd_len + in_size ||
  2627.                          sg_hd->result ) {
  2628.           /* some error happened */
  2629.           fprintf( stderr, "write(generic) result = 0x%x cmd = 0x%x\n",
  2630.                       sg_hd->result, i_buff[SCSI_OFF] );
  2631.           perror("");
  2632.           return status;
  2633.       }
  2634.  
  2635.       if (!o_buff) o_buff = i_buff;       /* buffer pointer check */
  2636.  
  2637.       /* retrieve result */
  2638.       status = read( fd, o_buff, SCSI_OFF + out_size);
  2639.       if ( status < 0 || status != SCSI_OFF + out_size || sg_hd->result ) {
  2640.           /* some error happened */
  2641.           fprintf( stderr, "read(generic) result = 0x%x cmd = 0x%x\n",
  2642.                   sg_hd->result, o_buff[SCSI_OFF] );
  2643.           fprintf( stderr, "read(generic) sense "
  2644.                   "%x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n",
  2645.                   sg_hd->sense_buffer[0],         sg_hd->sense_buffer[1],
  2646.                   sg_hd->sense_buffer[2],         sg_hd->sense_buffer[3],
  2647.                   sg_hd->sense_buffer[4],         sg_hd->sense_buffer[5],
  2648.                   sg_hd->sense_buffer[6],         sg_hd->sense_buffer[7],
  2649.                   sg_hd->sense_buffer[8],         sg_hd->sense_buffer[9],
  2650.                   sg_hd->sense_buffer[10],        sg_hd->sense_buffer[11],
  2651.                   sg_hd->sense_buffer[12],        sg_hd->sense_buffer[13],
  2652.                   sg_hd->sense_buffer[14],        sg_hd->sense_buffer[15]);
  2653.           perror("");
  2654.       }
  2655.       /* Look if we got what we expected to get */
  2656.       if (status == SCSI_OFF + out_size) status = 0; /* got them all */
  2657.  
  2658.       return status;  /* 0 means no error */
  2659.   }
  2660.  
  2661.   #define INQUIRY_CMD     0x12
  2662.   #define INQUIRY_CMDLEN  6
  2663.   #define INQUIRY_REPLY_LEN 96
  2664.   #define INQUIRY_VENDOR  8       /* Offset in reply data to vendor name */
  2665.  
  2666.   /* request vendor brand and model */
  2667.   static unsigned char *Inquiry ( void )
  2668.   {
  2669.     unsigned char Inqbuffer[ SCSI_OFF + INQUIRY_REPLY_LEN ];
  2670.     unsigned char cmdblk [ INQUIRY_CMDLEN ] =
  2671.         { INQUIRY_CMD,  /* command */
  2672.                     0,  /* lun/reserved */
  2673.                     0,  /* page code */
  2674.                     0,  /* reserved */
  2675.     INQUIRY_REPLY_LEN,  /* allocation length */
  2676.                     0 };/* reserved/flag/link */
  2677.  
  2678.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  2679.  
  2680.     /*
  2681.      * +------------------+
  2682.      * | struct sg_header | <- cmd
  2683.      * +------------------+
  2684.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  2685.      * +------------------+
  2686.      */
  2687.  
  2688.     if (handle_scsi_cmd(sizeof(cmdblk), 0, cmd,
  2689.                         sizeof(Inqbuffer) - SCSI_OFF, Inqbuffer )) {
  2690.         fprintf( stderr, "Inquiry failed\n" );
  2691.         exit(2);
  2692.     }
  2693.     return (Inqbuffer + SCSI_OFF);
  2694.   }
  2695.  
  2696.   #define TESTUNITREADY_CMD 0
  2697.   #define TESTUNITREADY_CMDLEN 6
  2698.  
  2699.   #define ADD_SENSECODE 12
  2700.   #define ADD_SC_QUALIFIER 13
  2701.   #define NO_MEDIA_SC 0x3a
  2702.   #define NO_MEDIA_SCQ 0x00
  2703.   int TestForMedium ( void )
  2704.   {
  2705.     /* request READY status */
  2706.     static unsigned char cmdblk [TESTUNITREADY_CMDLEN] = {
  2707.         TESTUNITREADY_CMD, /* command */
  2708.                         0, /* lun/reserved */
  2709.                         0, /* reserved */
  2710.                         0, /* reserved */
  2711.                         0, /* reserved */
  2712.                         0};/* reserved */
  2713.  
  2714.     memcpy( cmd + SCSI_OFF, cmdblk, sizeof(cmdblk) );
  2715.  
  2716.     /*
  2717.      * +------------------+
  2718.      * | struct sg_header | <- cmd
  2719.      * +------------------+
  2720.      * | copy of cmdblk   | <- cmd + SCSI_OFF
  2721.      * +------------------+
  2722.      */
  2723.  
  2724.     if (handle_scsi_cmd(sizeof(cmdblk), 0, cmd,
  2725.                               0, NULL)) {
  2726.         fprintf (stderr, "Test unit ready failed\n");
  2727.         exit(2);
  2728.     }
  2729.  
  2730.     return
  2731.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SENSECODE) !=
  2732.                                                           NO_MEDIA_SC ||
  2733.      *(((struct sg_header*)cmd)->sense_buffer +ADD_SC_QUALIFIER) !=
  2734.                                                           NO_MEDIA_SCQ;
  2735.   }
  2736.  
  2737.   void main( void )
  2738.   {
  2739.     fd = open(DEVICE, O_RDWR);
  2740.     if (fd < 0) {
  2741.       fprintf( stderr, "Need read/write permissions for "DEVICE".\n" );
  2742.       exit(1);
  2743.     }
  2744.  
  2745.     /* print some fields of the Inquiry result */
  2746.     printf( "%s\n", Inquiry() + INQUIRY_VENDOR );
  2747.  
  2748.     /* look if medium is loaded */
  2749.     if (!TestForMedium()) {
  2750.       printf("device is unloaded\n");
  2751.     } else {
  2752.       printf("device is loaded\n");
  2753.     }
  2754.   }
  2755.